The <script> element contains XddlScript. The <script> element appears as a child of the <type> element and is used to specify or refine a field's description when simple <enum> types are not adequate.
XddlScript is a powerful new feature of XDDL and is still under development. The language is Lua based, and the api is currently experimental and likely to change in the future.
Documentation on Lua can be found at www.lua.org.
The ultimate goal of the <script> element is to set a field's (or
property's) description. This is done by setting a variable named
description to a string. Here's a simple example that uses a <script> to
treat a value as an ascii string.
<type id="string">
<script>
description = string.format("%s", ascii());
</script>
</type>
The ascii() function is an XddlScript function that interprets the current
value as an ASCII string.
The following table lists all the currently supported XddlScript functions and is subject to change. The function availability when used used by <field> or <prop> elements is also noted.
| Function | fields | props | Description |
|---|---|---|---|
| ascii | yes | Return an the current value as an ASCII string | |
| ascii7 | yes | Return an the current value as a 7 bit ASCII string | |
| Description(name) | yes | yes | Return the description of a previous field |
| EnumValue | yes | yes | Return the <enum> description of the current value if it has one |
| Value(name) | yes | yes | Return the value of another field |
| slice(offset, length) | yes | Slice a field into pieces, see description below | |
| TwosComplement | yes | Return the current value as a two's complement integer | |
| search(name) | yes | yes | Return the description of a node in the message by name |
The ascii() string does not have to be null terminated. However, if
it is null terminated, the characters after the termination character will
be ignored. Any non-printable characters will be printed as periods.
Description() will return the description of node that is in scope.
Whereas search() will do a recursive descent depth-first search for a field from the
top of the message.
The slice() function can take the current value and return a value of just a
bit range, a subset of the entire bitstring that makes up the value. A
good example is taking a 32-bit IP address type and representing it in the
familiar dot notation:
<type id="ip_address">
<script>
description = string.format("%d.%d.%d.%d", slice(0, 8), slice(8, 8), slice(16, 8), slice(24, 8))
</script>
</type>