384
|
1 --[[ rPrint(struct, [limit], [indent]) Recursively print arbitrary data.
|
|
2 Set limit (default 100) to stanch infinite loops.
|
|
3 Indents tables as [KEY] VALUE, nested tables as [KEY] [KEY]...[KEY] VALUE
|
|
4 Set indent ("") to prefix each line: Mytable [KEY] [KEY]...[KEY] VALUE
|
|
5 https://gist.github.com/stuby/5445834#file-rprint-lua
|
|
6 --]]
|
|
7 function rPrint(s, l, i) -- recursive Print (structure, limit, indent)
|
|
8 l = (l) or 100; i = i or ""; -- default item limit, indent string
|
|
9 if (l<1) then print "ERROR: Item limit reached."; return l-1 end;
|
|
10 local ts = type(s);
|
|
11 if (ts ~= "table") then print (i,ts,s); return l-1 end
|
|
12 print (i,ts); -- print "table"
|
|
13 for k,v in pairs(s) do -- print "[KEY] VALUE"
|
|
14 l = rPrint(v, l, i.."\t["..tostring(k).."]");
|
|
15 if (l < 0) then break end
|
|
16 end
|
|
17 return l
|
|
18 end
|