This is automatically generated documentation. Edit after the "COMMENTS" heading; changes to the main body will be lost.
Script -- Click element; script a Click router configuration
Script(INSTRUCTIONS...)
Ports: none
Package: standard (core)
The Script element implements a simple scripting language useful for controlling Click configurations. Scripts can set variables, call handlers, wait for prodding from other elements, and stop the router.
Each configuration argument is an instruction (except for optional keywords; see below). Script generally processes these instructions sequentially.
In all cases, text arguments are subject to substitutions; see below.
set VAR TEXT'init VAR TEXT'print [>FILE | >>FILE] [TEXT | HANDLER]'print's argument starts with a letter, '@', or '_', then it is treated as a read handler. Otherwise, it is treated as quoted text; Script prints the unquoted version. For example, assuming the 'c.count' read handler returns "0": print c.count => 0 print "c.count" => c.count print '"c.count"' => "c.count" set x c.count print $x => c.count print $($x) => 0
read HANDLER [ARG...]'print' instruction.
write HANDLER [ARG...]'readq HANDLER [ARG...]', 'writeq HANDLER [ARG...]'read and write, but removes one layer of quoting from the ARGs before calling the handler.
pause [COUNT]'wait TIME'
label LABEL'goto LABEL [CONDITION]'goto exit [CONDITION]' or 'goto end [CONDITION]' ends execution of the script, much like an 'exit' or 'end' instruction.loop'return [VALUE]'run handler.exit', 'end'exit' instruction does not reinstall the script, whereas the 'end' instruction does.Scripts come in several types, including active scripts, which start running as soon as the configuration is loaded; passive scripts, which run only when prodded; signal scripts, which run in response to a signal; and driver scripts, which are active scripts that also control when the driver stops. The optional TYPE keyword argument is used to select a script type. The types are:
ACTIVEPASSIVErun handler. Passive scripts can help build complex handlers from existing simple ones; for example, here's a passive script whose s.run read handler returns the sum of two Counter handlers. ... c1 :: Counter ... c2 :: Counter ... s :: Script(TYPE PASSIVE, return $(add $(c1.count) $(c2.count))) Within the script, the run handler's arguments, if any, are available via the $args variable. The first, second, and so forth space-separated portions of $args are available via the $1, $2, ... variables.
DRIVERSIGNAL SIGNO...
Text in most Script instructions undergoes variable substitution. References to script variables, such as '$x', are replaced by the variable text. Additionally, the form '$(HANDLER [ARG...])' can be used to interpolate a read handler's value. Variable and handler references can be nested inside a '$(...)' block. For example, the following script will print 0, 1, 2, 3, and 4 on separate lines, then exit. Note the use of Script's arithmetic handlers.
s :: Script(set x 0,
label begin_loop,
print $x,
set x $(s.add $x 1),
goto begin_loop $(s.lt $x 5),
stop);
This can be further shortened since local handler references do not require the element name. Thus, "$(s.add ...)" can be written "$(add ...)", as below.
Script(set x 0,
label begin_loop,
print $x,
set x $(add $x 1),
goto begin_loop $(lt $x 5),
stop);
pause or wait). A numeric argument will step past that many blocking instructions.return' instruction, then the handler returns with that value.add 10 5 2' returns "17". (At user level, the arithmetic and comparison operators can parse floating-point numbers as well as integers.)sub 10 5 2' returns "3".idiv' handler truncates its result to an integer and returns that, whereas the 'div' handler returns a floating-point number; in the kernel, 'idiv' and 'div' both perform integer division.eq 10
0xA' returns "true", but 'le 9 8' returns "false". If either parameter cannot be interpreted as a number, performs a string comparison. For example, 'eq 10x 10x' return "true".sprintf "%05x" 127' returns "0007F".Generated by 'click-elem2man' from '../elements/standard/script.hh' on 18/Jul/2007.