Skip to content

Latest commit

 

History

History
42 lines (37 loc) · 1.03 KB

dumptable.lua

File metadata and controls

42 lines (37 loc) · 1.03 KB
 
Dec 24, 2013
Dec 24, 2013
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
function dumptable(tabname, tab, depth)
if depth == nil then -- first call, before any recursion?
depth = 1
end
if tabname ~= nil then
if tab == nil then
print(tabname .. " = nil")
return
else
print(tabname .. " = {")
end
end
local depthstr = ""
for i=1,(depth*4) do
depthstr = depthstr .. " "
end
if tab.DUMPTABLE_ITERATED then
print(depthstr .. "(...circular reference...)")
else
tab.DUMPTABLE_ITERATED = true
for k,v in pairs(tab) do
if type(v) == "table" then
print(depthstr .. tostring(k) .. " = {")
dumptable(nil, v, depth + 1)
print(depthstr .. "}")
else
if k ~= "DUMPTABLE_ITERATED" then
print(depthstr .. tostring(k) .. " = " .. tostring(v))
end
end
end
tab.DUMPTABLE_ITERATED = nil
end
if tabname ~= nil then
print("}")
end
end