Function calls return a value, such as the result of a calculation. The way a function is called depends on where the call (target) function is declared. The following sections describe three function calls supported by WMLScript 1.1:
A function that is declared and called in the same file.
The following is an example of a local script function:
function test2 (param) {
return test1 (param+1);
};
function test1 (val) {
return val*val;
};
Local script functions can be called simply by providing the function name and a comma-separated list of arguments. The number of arguments must match the number of parameters accepted by the function.
A local script function can be called before it has been declared.
A function that is declared in an external file.
The following is an example of an external function:
use url OtherScript "http://www.host.com/script";
function test3(param) {
return OtherScript#test2(param+1);
};
The external function call must be prefixed with the name of the external file.
You must use the use url pragma to specify the external file. This pragma maps the external unit to a name that can be used within the function declaration. This name and the hash symbol (#) are used to prefix the standard function call syntax.
A function that calls a WMLScript 1.1 standard library function.
The following is an examle of a library function:
function test4(param) {
return Float.sqrt(Lang.abs(param)+1);
};
You can call a library function by prefixing the function name with the name of the library and the dot symbol (.). In the example above, function abs is prefixed by library Lang.