annotate Resources/Toolbox.lua @ 1208:6502517fd4af

improved doc thanks to Vincent Kersten
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 03 Nov 2014 16:45:35 +0100
parents 921532f67770
children d710ea64f0fd
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)
1006
649d47854314 proper handling of metadata in Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 418
diff changeset
9 l = (l) or 100; -- default item limit
649d47854314 proper handling of metadata in Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 418
diff changeset
10 i = i or ""; -- indent string
384
18fe778eeb95 wrapper around lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 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
12 local ts = type(s);
18fe778eeb95 wrapper around lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 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
14 print (i,ts); -- print "table"
18fe778eeb95 wrapper around lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 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
16 l = PrintRecursive(v, l, i.."\t["..tostring(k).."]");
384
18fe778eeb95 wrapper around lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 if (l < 0) then break end
18fe778eeb95 wrapper around lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 end
18fe778eeb95 wrapper around lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 return l
18fe778eeb95 wrapper around lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 end
418
b79bf2f4ab2e execution of lua through REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 397
diff changeset
21
1010
160dfe770618 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
22
160dfe770618 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
23
160dfe770618 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
24
160dfe770618 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
25 function _InitializeJob()
160dfe770618 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
26 _job = {}
160dfe770618 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
27 end
160dfe770618 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
28
160dfe770618 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
29
160dfe770618 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
30 function _AccessJob()
160dfe770618 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
31 return _job
160dfe770618 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
32 end
160dfe770618 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
33
160dfe770618 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
34
160dfe770618 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
35 function SendToModality(instanceId, modality)
160dfe770618 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
36 if instanceId == nil then
160dfe770618 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
37 error('Cannot send a nonexistent instance')
160dfe770618 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
38 end
160dfe770618 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
39
160dfe770618 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
40 table.insert(_job, {
160dfe770618 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
41 Operation = 'store-scu',
160dfe770618 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
42 Instance = instanceId,
160dfe770618 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
43 Modality = modality
160dfe770618 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
44 })
160dfe770618 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
45 return instanceId
160dfe770618 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
46 end
160dfe770618 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
47
160dfe770618 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
48
160dfe770618 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
49 function SendToPeer(instanceId, peer)
160dfe770618 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
50 if instanceId == nil then
160dfe770618 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
51 error('Cannot send a nonexistent instance')
160dfe770618 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
52 end
160dfe770618 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
53
160dfe770618 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
54 table.insert(_job, {
160dfe770618 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
55 Operation = 'store-peer',
160dfe770618 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
56 Instance = instanceId,
160dfe770618 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
57 Peer = peer
160dfe770618 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
58 })
160dfe770618 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
59 return instanceId
160dfe770618 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
60 end
160dfe770618 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
61
160dfe770618 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
62
160dfe770618 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
63 function Delete(instanceId)
160dfe770618 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
64 if instanceId == nil then
160dfe770618 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
65 error('Cannot delete a nonexistent instance')
160dfe770618 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
66 end
160dfe770618 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
67
160dfe770618 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
68 table.insert(_job, {
160dfe770618 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
69 Operation = 'delete',
160dfe770618 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
70 Instance = instanceId
160dfe770618 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
71 })
160dfe770618 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
72 return nil -- Forbid chaining
160dfe770618 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
73 end
160dfe770618 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
74
160dfe770618 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
75
160dfe770618 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
76 function ModifyInstance(instanceId, replacements, removals, removePrivateTags)
160dfe770618 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
77 if instanceId == nil then
160dfe770618 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
78 error('Cannot modify a nonexistent instance')
160dfe770618 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
79 end
160dfe770618 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
80
160dfe770618 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
81 if instanceId == '' then
160dfe770618 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
82 error('Cannot modify twice an instance');
160dfe770618 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
83 end
160dfe770618 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
84
160dfe770618 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
85 table.insert(_job, {
160dfe770618 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
86 Operation = 'modify',
160dfe770618 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
87 Instance = instanceId,
160dfe770618 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
88 Replace = replacements,
160dfe770618 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
89 Remove = removals,
160dfe770618 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
90 RemovePrivateTags = removePrivateTags
160dfe770618 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
91 })
160dfe770618 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
92 return '' -- Chain with another operation
160dfe770618 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
93 end
160dfe770618 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
94
160dfe770618 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
95
1065
921532f67770 Lua scripts can invoke system commands, with CallSystem()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1010
diff changeset
96 function CallSystem(instanceId, command, args)
921532f67770 Lua scripts can invoke system commands, with CallSystem()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1010
diff changeset
97 if instanceId == nil then
921532f67770 Lua scripts can invoke system commands, with CallSystem()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1010
diff changeset
98 error('Cannot modify a nonexistent instance')
921532f67770 Lua scripts can invoke system commands, with CallSystem()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1010
diff changeset
99 end
921532f67770 Lua scripts can invoke system commands, with CallSystem()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1010
diff changeset
100
921532f67770 Lua scripts can invoke system commands, with CallSystem()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1010
diff changeset
101 table.insert(_job, {
921532f67770 Lua scripts can invoke system commands, with CallSystem()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1010
diff changeset
102 Operation = 'call-system',
921532f67770 Lua scripts can invoke system commands, with CallSystem()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1010
diff changeset
103 Instance = instanceId,
921532f67770 Lua scripts can invoke system commands, with CallSystem()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1010
diff changeset
104 Command = command,
921532f67770 Lua scripts can invoke system commands, with CallSystem()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1010
diff changeset
105 Arguments = args
921532f67770 Lua scripts can invoke system commands, with CallSystem()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1010
diff changeset
106 })
921532f67770 Lua scripts can invoke system commands, with CallSystem()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1010
diff changeset
107
921532f67770 Lua scripts can invoke system commands, with CallSystem()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1010
diff changeset
108 return instanceId
921532f67770 Lua scripts can invoke system commands, with CallSystem()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1010
diff changeset
109 end
921532f67770 Lua scripts can invoke system commands, with CallSystem()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1010
diff changeset
110
1010
160dfe770618 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
111
418
b79bf2f4ab2e execution of lua through REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 397
diff changeset
112 print('Lua toolbox installed')