
7 Scripting
23
7.3
Entering scripts
First, for a quick overview of the script language visit the
on the Digital Loggers web
site. Log in as admin and use the Scripting link to access the programming page.
Scripting is based on the
programming language. A brief introduction is done below, but you may want to
consult the general description, especially if you intend to write more complex scripts.
Script code is organized in functions. Configuration items which allow some scripting reaction to an event (reboot,
autoping failure, etc.) will ask you for the name of the function to call (you will be offered a list of the functions
defined in the script).
Script listing
Save
--[[ Power controller user script code.
The scripting implementation has changed, and is no longer compatible
with the older BASIC implementation. The most important changes are:
- Now Lua-based.
- No more line numbers, blocks of code identified by functions.
- Most of ON, OFF, etc. are kept as legacy functions, which can be called like
e.g ON(2345), ON("2345") or ON "2345", your choice.
Execution is still based on threads. Now threads are more visible and
manageable. Try starting some and you'll see them appearing in the
list.
Scripting samples are now available as snippets (below), separate from
the main script code. You can copy/paste them from/to the main script.
Stock snippets have names starting with 'default.'; changing or
creating snippets with such names is not recommended as your changes
may be erased on an upgrade.
]]--
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
User script source editor
You will need to define your functions to be able to use scripting. Simply putting calls to existing functions in the
script will not work. Functions are defined like this:
function my_function()
... statements go here ...
end
All functions defined this way will be usable from the web UI and callable externally. If you want to define a function
for internal use, not to be called from outside, prefix it with
local
:
local function my_internal_function()
... statements go here ...
end
Local functions declared this way must be placed before any function that uses it. If you want to move the definition
elsewhere and don't need to call the function before the definition, you can use the following structure:
local my_internal_function
... functions that use my_internal_function in bodies ...
function my_internal_function()
... statements go here ...
end
DLI LPC9 User’s Guide: 1.7.24.0
Содержание LPC9
Страница 1: ...DLI LPC9 User s Guide 1 7 24 0 ...
Страница 81: ......