-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmostacholes.lua
More file actions
80 lines (65 loc) · 1.67 KB
/
mostacholes.lua
File metadata and controls
80 lines (65 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
r = {}
r.mode = 'variables'
r.line = function()
local line = file.readline()
return line and r[r.mode](line)
end
r.variables = function(line)
local token = line:match('{#(.-)}')
if token then
token = loadstring('return ' .. token)()
if type(token) == 'table' and next(token) then
r.mode = 'non_empty_list'
r.pos = file.seek()
r.table = token
r.index = next(token)
elseif type(token) ~= 'table' and token then
r.mode = 'non_false_value'
else
r.mode = 'false_value_or_empty_list'
end
line = r.line()
else
for token in line:gmatch('{(.-)}') do
line = line:gsub('{' .. token .. '}', loadstring('return ' .. token), 1)
end
end
return line
end
r.non_false_value = function(line)
if line:match('{/(.-)}') then
r.mode = 'variables'
return r.line()
end
for token in line:gmatch('{(.-)}') do
line = line:gsub('{' .. token .. '}', loadstring('return ' .. token), 1)
end
return line
end
r.non_empty_list = function(line)
local token = line:match('{/(.-)}')
if token then
r.index = next(r.table, r.index)
if r.index then
file.seek('set', r.pos)
else
r.mode = 'variables'
r.pos = nil
r.table = nil
end
line = r.line()
else
for token in line:gmatch('{(.-)}') do
line =
token == '.' and
line.gsub('{.}', loadstring('return r.table[r.index]'), 1) or
line:gsub('{' .. token .. '}',
loadstring('return r.table[r.index][\'' .. token .. '\']'), 1)
end
end
return line
end
r.false_value_or_empty_list = function(line)
if line:match('{/(.-)}') then r.mode = 'variables' end
return r.line()
end