22
CONTENTS
7.4.2
Modern API
Modern API allows more object-oriented approach to scripting. You need to explicitly use the
delay()
function if
you use the modern API and need a delay. Note that the relay power-on sequence delay applies anyway.
Lua objects can have fields (data contained in the object) and methods (functions which affect the object's state).
Object fields are accessed with a dot
.
, like
meter.reading
. However, different object implementations in Lua
may use the colon
:
or the dot
.
to access the object's methods (
outlet:cycle()
or
outlet.cycle()
).
In the modern API, all objects use the dot
.
to access their methods, to prevent confusion.
Modern API objects and functions are grouped into several categories for convenience.
7.4.2.1
Core Lua functions
To make scripting safer, only a limited subset of Lua features is supported by sandboxing. The following Lua
standard library features are supported:
Globals:
_VERSION
,
assert
,
error
,
next
,
ipairs
,
pairs
,
pcall
,
xpcall
,
select
,
tonumber
,
tostring
,
type
,
unpack
.
string
library:
string.byte
,
string.char
,
string.find
,
string.format
,
string.gmatch
,
string.gsub
,
string.len
,
string.lower
,
string.match
,
string.rep
,
string.reverse
,
string.sub
,
string.upper
.
table
library:
table.insert
,
table.concat
,
table.maxn
,
table.remove
,
table.sort
.
math
library:
math.abs
,
math.acos
,
math.asin
,
math.atan
,
math.atan2
,
math.ceil
,
math.
←
-
cos
,
math.cosh
,
math.deg
,
math.exp
,
math.floor
,
math.fmod
,
math.frexp
,
math.huge
,
math.ldexp
,
math.log
,
math.log10
,
math.max
,
math.min
,
math.modf
,
math.pi
,
math.pow
,
math.rad
,
math.random
,
math.sin
,
math.sinh
,
math.sqrt
,
math.tan
,
math.tanh
.
os
library:
os.clock
,
os.difftime
,
os.date
,
os.time
.
Additionally,
_G
points to the sandbox environment.
7.4.2.2
Delay functions
The
delay
function accepts the number of seconds to wait as an argument (it is assumed to be the script step
delay if not specified). If a scripting thread doesn't call
delay()
or one of the legacy API functions every now and
then, it can't be terminated by
thread.kill
and will eventually be shut down by the runtime.
7.4.2.3
Relay management
The global variable
outlet
represents a Lua array of relay objects, which have methods
on
(switch on),
off
(switch off),
cycle
(cycle), and two fields
state
(reflects the current state of the relay) and
locked
(read-only
field telling if the relay is locked).
The variable name is chosen to match AC products.
Global constants
on
and
off
are
true
and
false
, respectively, useful to make scripts more readable, like
outlet[1].state=on
;
DLI DIN4 User’s Guide: 20170809T111540Z
Summary of Contents for DIN4
Page 1: ...DLI DIN4 User s Guide 20170809T111540Z ...
Page 57: ......