-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdumper.lua
43 lines (40 loc) · 895 Bytes
/
dumper.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
local function _dumper(seen,t)
if type(t) == 'table' then
if seen[ t ] then
return '\\'..tostring(t)
end
seen[ t ] = true
local keys = 0
for _,_ in pairs(t) do keys = keys + 1 end
if keys ~= #t then
local sub = {}
local prev = 0
for k,v in pairs(t) do
if type(k) == 'number' and k == prev + 1 then
prev = k
table.insert(sub,_dumper(seen,v))
else
table.insert(sub,tostring(k)..'='.._dumper(seen,v))
end
end
return '{'..table.concat(sub,'; ')..'}'
else
local sub = {}
for _,v in ipairs(t) do
table.insert(sub,_dumper(seen,v))
end
return '{'..table.concat(sub,', ')..'}'
end
elseif type(t) == 'number' then
return tostring(t)
elseif type(t) == 'string' then
return "'" .. t .. "'"
else
return tostring(t)
end
end
local function dumper(x)
return _dumper({},x)
end
rawset(_G, 'dumper', dumper)
return dumper