System information

Manual:Lua
47
Manual:Lua
Summary
Version 4.0beta3 introduces preliminary support for Lua scripting language
[1]
. Integration with console is still in
progress.
RouterOS v4 RC1 removes Lua support indefinetly
Changes in console
':' and '/' namespaces are merged. Lookup rules have been changed so as not to affect existing scripts:
Without leading ':' or '/' names are looked up starting from the current path.
With leading ':' and '/' names are looked up starting from the root of the hierarchy.
With leading '/' current path of all subcommands is set to the path of command.
With leading ':' current path of subcommands is kept the same as the current path of command.
Example:
/ip address { #changes current path
print #/ip address print
:queue simple print where interface=[get 0 interface]
#this 'get' is '/ip address get', because
#leading ':' does not change current path
#for subcommands
}
Value of type 'nothing' is gone.
Command 'nothing' returns same value as the empty command '[]'. It is kept for compatibility with earlier
versions.
Value of type 'error' is gone, console error handling is unified with the Lua error hadling.
'error' command now immedeately raises an exception.
New value type 'lua', holds arbitrary Lua values.
New command 'lua' that returns lua function created from the given source string.
Command can now also be a variable substitution, an expression or a command substitution. Result is evaluated.
Example:
global a [parse "/interface print"]; $a
($a)
[parse "/interface print"]
[lua "io.write 'this works\\n'"]
Global variables are shared between Lua and console scripts.
There is no ':log' command anymore, it is replace by four commands 'log info', 'log error', 'log warning', 'log
debug'. This change was necessary because of the root namespace merge. It preserves compatibility with previous
scripts, but note that name of log topic cannot be a result of an expression.
'/system script' items has new property 'language' that can be either 'cmd' or 'lua'. 'cmd' is for console scripts, 'lua'
is for Lua scripts.
New operator '%' that computes remainder.
Logical operators now treat all values except nil and 'false' as 'true'. Note that empty string, empty array, number
0, IP address 0.0.0.0 and similar values are treated as a 'true', this is consistent with the Lua behaviour. Previously