13
|
1 |
function dumptable(tabname, tab, depth)
|
|
2 |
if depth == nil then -- first call, before any recursion?
|
|
3 |
depth = 1
|
|
4 |
end
|
|
5 |
|
|
6 |
if tabname ~= nil then
|
|
7 |
if tab == nil then
|
|
8 |
print(tabname .. " = nil")
|
|
9 |
return
|
|
10 |
else
|
|
11 |
print(tabname .. " = {")
|
|
12 |
end
|
|
13 |
end
|
|
14 |
|
|
15 |
local depthstr = ""
|
|
16 |
for i=1,(depth*4) do
|
|
17 |
depthstr = depthstr .. " "
|
|
18 |
end
|
|
19 |
|
|
20 |
if tab.DUMPTABLE_ITERATED then
|
|
21 |
print(depthstr .. "(...circular reference...)")
|
|
22 |
else
|
|
23 |
tab.DUMPTABLE_ITERATED = true
|
|
24 |
for k,v in pairs(tab) do
|
|
25 |
if type(v) == "table" then
|
|
26 |
print(depthstr .. tostring(k) .. " = {")
|
|
27 |
dumptable(nil, v, depth + 1)
|
|
28 |
print(depthstr .. "}")
|
|
29 |
else
|
|
30 |
if k ~= "DUMPTABLE_ITERATED" then
|
|
31 |
print(depthstr .. tostring(k) .. " = " .. tostring(v))
|
|
32 |
end
|
|
33 |
end
|
|
34 |
end
|
|
35 |
tab.DUMPTABLE_ITERATED = nil
|
|
36 |
end
|
|
37 |
|
|
38 |
if tabname ~= nil then
|
|
39 |
print("}")
|
|
40 |
end
|
|
41 |
end
|
|
42 |
|