In X/script source file you can define two types of user functions: standard and assignable.
Standard function are the commonly used functions in any programming language, while assignable are special function for X/script that can be used as left side in an assignment code.
Function prototypes
Function can be optionally prototyped so can be called before they are actually defined. To prototype standard and assignable functions use the forward keyword with following syntax:
FORWARD <name> ([<argument>, ... ]) [:<result>] FORWARD ASSIGNABLE <name> ([<argument>, ...]): <type> |
---|
where:
•<name> is the name of the function;
•<arguments> are optional function arguments;
•<result> is an optional return data type for the standard function;
•<type> is the assignment data type for the assignable function.
Functions arguments are defined as:
<argtype>[<argname> [=<argdefault>]] |
---|
where:
•<argtype> is the argument data type;
•<argname> optional argument name;
•<argdefault> optional argument default value;
Function declaration
To defined standard functions use the code keyword with following syntax:
CODE <name> ([<argument>, ... ]) [:<result>] ... [RETURN <value>] END[CODE] |
---|
In very similar way you can defined assignable functions:
CODE ASSIGNABLE <name> ([<argument>, ...]): <type><aname> ... END[CODE] |
---|
where:
•<name> is the name of the function;
•<arguments> are optional function arguments;
•<result> is a optional return data type for standard function;
•<type> is the assignment data type for an assignable function.
•<aname> is the assignment argument name (variable that received the result of assignment right side expression).
•<value> is the optional return value (needed if function define a valid <result>) used with RETURN statement.
Function arguments are defined as:
<argtype> <argname> [=<argdefault(*)>] |
---|
where:
•<argtype> is the argument data type;
•<argname> argument name;
•<argdefault> optional argument default value, can be used only if the function has never been prototyped before.
Remind that:
•assignable functions cannot have a return value.
•a function with result type defined must return a value with the RETURN statement.
•nested functions cannot be declared (e.g. declaring a function inside a function)
•a standard function and an assignable function can have the same name
•functions with the same name but different arguments are different functions.
Internal function declaration
Internal functions are special functions to be used only for VMI interface declaration. The declaration is very similar to the prototype but uses the internal keyword instead.
INTERNAL <id> <name> ([<argument>, ... ]) [:<result>] INTERNAL <id> ASSIGNABLE <name> ([<argument>, ...]): <type> |
---|
Where <id> is the internal identification code for the VMI interface. For other parameters see function prototypes.
In most cases of X/script embedding, internal declarations are built-in in the X/script compiler itself, so there is no need to include files and the declaration itself is more safe.
Warning: never define an internal function without knowing well what you are doing. You can cause serious damage and crashes to your system and loose important data or files.