Mercurial > hg > orthanc
comparison Resources/Toolbox.lua @ 397:941ea46e9e26 lua-scripting
lua filter of new instances
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 02 May 2013 16:34:00 +0200 |
parents | 9784f19f7e1b |
children | b79bf2f4ab2e |
comparison
equal
deleted
inserted
replaced
394:9784f19f7e1b | 397:941ea46e9e26 |
---|---|
1 --[[ printRecursive(struct, [limit], [indent]) Recursively print arbitrary data. | 1 --[[ PrintRecursive(struct, [limit], [indent]) Recursively print arbitrary data. |
2 Set limit (default 100) to stanch infinite loops. | 2 Set limit (default 100) to stanch infinite loops. |
3 Indents tables as [KEY] VALUE, nested tables as [KEY] [KEY]...[KEY] VALUE | 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 | 4 Set indent ("") to prefix each line: Mytable [KEY] [KEY]...[KEY] VALUE |
5 Source: https://gist.github.com/stuby/5445834#file-rprint-lua | 5 Source: https://gist.github.com/stuby/5445834#file-rprint-lua |
6 --]] | 6 --]] |
7 | 7 |
8 function printRecursive(s, l, i) -- recursive Print (structure, limit, indent) | 8 function PrintRecursive(s, l, i) -- recursive Print (structure, limit, indent) |
9 l = (l) or 100; i = i or ""; -- default item limit, indent string | 9 l = (l) or 100; i = i or ""; -- default item limit, indent string |
10 if (l<1) then print "ERROR: Item limit reached."; return l-1 end; | 10 if (l<1) then print "ERROR: Item limit reached."; return l-1 end; |
11 local ts = type(s); | 11 local ts = type(s); |
12 if (ts ~= "table") then print (i,ts,s); return l-1 end | 12 if (ts ~= "table") then print (i,ts,s); return l-1 end |
13 print (i,ts); -- print "table" | 13 print (i,ts); -- print "table" |
14 for k,v in pairs(s) do -- print "[KEY] VALUE" | 14 for k,v in pairs(s) do -- print "[KEY] VALUE" |
15 l = printRecursive(v, l, i.."\t["..tostring(k).."]"); | 15 l = PrintRecursive(v, l, i.."\t["..tostring(k).."]"); |
16 if (l < 0) then break end | 16 if (l < 0) then break end |
17 end | 17 end |
18 return l | 18 return l |
19 end | 19 end |