-
Notifications
You must be signed in to change notification settings - Fork 3
/
dump.lua
55 lines (49 loc) · 1.29 KB
/
dump.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
module(..., package.seeall)
-- Dump an XML table
function dump(_class, no_func, depth)
if (not _class) then
print ("dump: not a class.");
return;
end
if(depth==nil) then depth=0; end
local str="";
for n=0,depth,1 do
str=str.."\t";
end
if (depth > 10) then
print ("Oops, running away! Depth is "..depth)
return
end
print (str.."["..type(_class).."]");
print (str.."{");
if (type(_class) == "table") then
for i,field in pairs(_class) do
if(type(field)=="table") then
local fn = tostring(i)
if (string.sub(fn,1,2) == "__") then
print (str.."\t"..tostring(i).." = (not expanding this internal table)");
else
print (str.."\t"..tostring(i).." =");
dump(field, no_func, depth+1);
end
else
if(type(field)=="number") then
print (str.."\t"..tostring(i).."="..field);
elseif(type(field) == "string") then
print (str.."\t"..tostring(i).."=".."\""..field.."\"");
elseif(type(field) == "boolean") then
print (str.."\t"..tostring(i).."=".."\""..tostring(field).."\"");
else
if(not no_func)then
if(type(field)=="function")then
print (str.."\t"..tostring(i).."()");
else
print (str.."\t"..tostring(i).."<userdata=["..type(field).."]>");
end
end
end
end
end
end
print (str.."}");
end