index

Global declarations

All global declarations share the same namespace so their names may not conflict. This includes extended data types and built in functions registered by the host application. Also, all declarations are visible to all, e.g. a function to be called do not have to be declared above the function that calls it.

Functions

FUNCTION       ::= TYPE IDENTIFIER '(' PARAMETERS ')' '{' IMPLEMENTATION '}'
PARAMETERS     ::= (TYPE ('&' ('in' | 'out' | 'inout'))? IDENTIFIER?)*
TYPE           ::= <a data type>
IDENTIFIER     ::= <the function name>
IMPLEMENTATION ::= <zero or more statements>

TYPE is one of the available return data types, e.g. void, int, or bool.

Parameters are declared with data type, optionally & for data sent by reference and optionally an identifier to access the parameter from within the function. If more than one parameter is specified they are separated with commas.

For parameters sent by reference, i.e. with the & modifier it is necessary in which direction the value is passed, in, out, or inout, e.g. &out. For parameters marked with in the value is passed in to the function, and for parameters marked with out the value is returned from the function. Note that if the parameter is marked as inout, the argument is copied twice, once when going in to the function and once when going out, this can lead to a performance impact, so should be avoided if possible.

Parameters can also be declared as const which prohibits the alteration of their value. It is good practice to declare variables that will not be changed as const, because it makes for more readable code and the compiler is also able to take advantage of it some times.

The IMPLEMENTATION is written through a series of statements.

Note that although functions that return types by references can't be declared by scripts you may still see functions like these if the host application defines them. In that case you the returned value may also be used as the target in assignments.

Variables

DECLARATION ::= TYPE IDENTIFIER ('=' EXPRESSION)? (',' IDENTIFIER ('=' EXPRESSION)?)* ';'
TYPE        ::= <a data type>
IDENTIFIER  ::= <the variable name>
EXPRESSION  ::= <an expression whose value will initialize the variable>

TYPE is one of the available data types. The expression may not call any functions, assign any variables. The expression doesn't have to be constant, and it can even use the condition operator ?:.

Variables declared globally like this are accessible from all functions. The value of the variables are initialized at compile time and any changes are maintained between calls. If a global variable holds a memory resource, e.g. an bstr, its memory is released when the script engine is reset.

Structures

DECLARATION ::= 'struct' IDENTIFIER '{' PROP* '}' ';'
PROP        ::= TYPE IDENTIFIER ';'
TYPE        ::= <a data type>

With structures the script writer can declare new data types that hold groups of values.

Imports

IMPORT         ::= 'import' TYPE IDENTIFIER '(' PARAMETERS ')' 'from' STRING ';'
PARAMETERS     ::= (TYPE ('&' ('in' | 'out' | 'inout'))? IDENTIFIER?)*
TYPE           ::= <a data type>
IDENTIFIER     ::= <the function name>
STRING         ::= <a text string between double quotes>

TYPE is one of the available return data types, e.g. void, int, or bool.

This statement allow a script to declare function prototypes that will be imported from other modules. If the application support this, then the functions are bound after the module has been compiled, and can even be exchanged while running the script.

Note: The from keyword is not a reserved keyword and can therefore be used as normal for function and variable names.

top