annotate Resources/Toolbox.lua @ 955:743a75b14bef plugins

merge mainline -> plugins
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 25 Jun 2014 15:37:48 +0200
parents b79bf2f4ab2e
children 649d47854314
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
397
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 394
diff changeset
1 --[[ PrintRecursive(struct, [limit], [indent]) Recursively print arbitrary data.
384
18fe778eeb95 wrapper around lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 Set limit (default 100) to stanch infinite loops.
18fe778eeb95 wrapper around lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 Indents tables as [KEY] VALUE, nested tables as [KEY] [KEY]...[KEY] VALUE
18fe778eeb95 wrapper around lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 Set indent ("") to prefix each line: Mytable [KEY] [KEY]...[KEY] VALUE
394
9784f19f7e1b path relative to configuration path, list of lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 384
diff changeset
5 Source: https://gist.github.com/stuby/5445834#file-rprint-lua
384
18fe778eeb95 wrapper around lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 --]]
394
9784f19f7e1b path relative to configuration path, list of lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 384
diff changeset
7
397
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 394
diff changeset
8 function PrintRecursive(s, l, i) -- recursive Print (structure, limit, indent)
384
18fe778eeb95 wrapper around lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 l = (l) or 100; i = i or ""; -- default item limit, indent string
18fe778eeb95 wrapper around lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 if (l<1) then print "ERROR: Item limit reached."; return l-1 end;
18fe778eeb95 wrapper around lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 local ts = type(s);
18fe778eeb95 wrapper around lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 if (ts ~= "table") then print (i,ts,s); return l-1 end
18fe778eeb95 wrapper around lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 print (i,ts); -- print "table"
18fe778eeb95 wrapper around lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 for k,v in pairs(s) do -- print "[KEY] VALUE"
397
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 394
diff changeset
15 l = PrintRecursive(v, l, i.."\t["..tostring(k).."]");
384
18fe778eeb95 wrapper around lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 if (l < 0) then break end
18fe778eeb95 wrapper around lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 end
18fe778eeb95 wrapper around lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 return l
18fe778eeb95 wrapper around lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 end
418
b79bf2f4ab2e execution of lua through REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 397
diff changeset
20
b79bf2f4ab2e execution of lua through REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 397
diff changeset
21 print('Lua toolbox installed')