-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.lua
62 lines (49 loc) · 1.12 KB
/
main.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
local function _print(tab,indent,same)
local sg=tostring(tab).." {\n"
for key,value in pairs(tab) do
local line=indent.." ["..tostring(key).."]>"
if type(value)=="table" then
if same[tostring(value)] then
line = line.."*"..tostring(value)
else
same[tostring(value)]=true
local len=string.len(line)
local newIndent=string.rep(" ",len)
line = line.._print(value,newIndent,same)
end
else
line = line..tostring(value)
end
line=line.."\n"
sg=sg..line
end
sg=sg..indent.."}"
return sg
end
local function pprint(tab)
local same={-- éviter les répétitions
[tostring(tab)]=true
}
local _str=_print(tab,"",same)
print(_str)
end
--Exemple
local t={1,{"abc",{}}}
t[{}]={}
t[function() end]={[t]=t}
pprint(t)
--[[ output
table: 0B1349C0 {
[1]>1
[2]>table: 0B134A38 {
[1]>abc
[2]>table: 0B134C40 {
}
}
[table: 0B134AB0]>table: 0B134C18 {
}
[function: 0AAD0168]>table: 0B1348D0 {
[table: 0B1349C0]>*table: 0B1349C0
}
}
]]--