7 Scripting
31
If you overwrite the whole
sticky
table like this:
function init_sticky()
sticky={local_var=0,global_var=0}
end
the changes will only apply from that environment on (threads started in previous environments will be unaffected).
In both cases you'll need to call
init_sticky
once explicitly before calling
thread_creator
, which might be
inconvenient. Alternatives include setting default values, if they are not nil, on entry to functions that use the values:
function thread_fn()
sticky.local_var=sticky.local_var or 0
sticky.global_var=sticky.global_var or 0
while true do
...
sticky.local_var=sticky.lo1
sticky.global_var=sticky.glo1
...
end
end
or writing code that it handles default nil values transparently:
function thread_fn()
while true do
...
sticky.local_var=(sticky.local_var or 0)+1
sticky.global_var=(sticky.global_var or 0)+1
...
end
end
Variables created this way are not persisted across reboots; see
for those that are.
7.6.2.8
Externally accessible state management
Local and global variables of scripts are in general not accessible from outside the scripting engine, e.g. they cannot
be manipulated from the REST-like API.
You can create entries in the global
external
table, like this:
external["variable"]="some value"
external["variable2"]=12345
and have them accessible under
/restapi/script/variables/
variablename
/
.
You can only store strings, numbers, booleans or nil into this table at nonempty string indices. Attempts to use
nonstring keys, or table or function values, or overwrite the
external
table, will result in an error:
external={}
-- error
external["x"]=outlet -- error
external[5]=external -- error
The
external
table otherwise behaves like
sticky
; in particular, variables created this way are not persisted
across reboots; see
for those that are.
DLI LPC9 User’s Guide: 1.7.24.0
Summary of Contents for LPC9
Page 1: ...DLI LPC9 User s Guide 1 7 24 0 ...
Page 81: ......