-
Notifications
You must be signed in to change notification settings - Fork 0
/
dict.lua
46 lines (40 loc) · 1.09 KB
/
dict.lua
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
local dict = {}
dict.parse = function(dc)
if type(dc) == "table" then
local result = {}
for k, v in pairs(dc) do
table.insert(result, k.." => "..v)
end
return table.concat(result, "\n")
elseif type(dc) == "string" then
local result = {}
local resultV = {}
local resultK = {}
for i in string.gmatch(dc, "%S+") do
table.insert(result, i)
end
for k, v in pairs(result) do
if v == "=>" then
table.remove(result, k)
else
table.insert(resultK, v)
table.insert(resultV, v)
end
end
for i=0, #resultV do
i = i+1
table.remove(resultV, i)
end
for i=1, #resultK do
i = i+1
table.remove(resultK, i)
end
local result = {}
for i=1, #resultK do
result[resultK[i]] = resultV[i]
end
else
error("table or string to parse expected, got"..type(dc))
end
end
return dict