WMLScript Developer's Guide

[Cover] [Previous Section] [Next Section] [Index]

Current chapter: Chapter 7 - Functions
Section 40 out of 57 total sections , Section 3 out of 3 sections in this chapter


Function Calls

Function calls return a value, such as the result of a calculation. The way you call a function depends on where the call (target) function is declared. The following sections describe the three function calls WMLScript supports:



Local Script Functions

A local script function is one that is declared and called in the same file. 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 its declaration.

A local script function cannot be called from any other file. Local script functions are roughly equivalent to protected or private member functions in C++ programs.

The following is an example of a local script function:

function test2 (param) {  
    return test1 (param+1);  
}  
function test1 (val) {  
    return val*val;  
}  


External Functions

An external function is one that is accessible to files other than the one in which the external function is declared. External functions, and their parameters and/or variables, are the primary means of interaction between WMLScripts and WML files.

Use external functions as entry points into a WMLScript file from other WMLScripts or WML files. External functions can accept both parameters and variables when called from other files.

External functions are roughly equivalent to public member functions in C++ programs.

To declare an external function, use the extern keyword before the function name.

You must use the use url pragma to specify the name and location of the external file when calling an external function in a WMLScript. This pragma maps the external script file to a name that can be used within the function declaration. Prepend this name and the hash symbol (#) to the standard function call syntax.

For this example, assume that the WMLScript file name is OtherScript and that it is located at http://www.host.com/script. The following is an example of an external function declaration:

//Filename: OtherScript; URL: http://www.host.com/script  
 
extern function test2(param) {  
//function implementation  
    return ext_param;  
}  

The following is an example of calling an external function from a WMLScript:

//file name and full URL of the eternal function "test2"  
use url OtherScript "http://www.host.com/script";  
 
function test3(param) {  
    return OtherScript#test2(param+1); //external function  
}  


Library Functions

A library function is one that calls a WMLScript standard library function. You can call a library function by prepending the name of the library and the dot operator (.) to the function name. In the example below, function sqrt is found in the Float library and function abs is found in the Lang library.

The following is an example of a library function:

function test4(param) {  
    return Float.sqrt(Lang.abs(param)+1);  
}  


[Cover] [Previous Section] [Next Section] [Index]


Part Number DKDS-41-002, UP.SDK Release 4.1, December 2000

Copyright © 1994-2000 Openwave Systems Inc. All rights reserved.
Please send comments and questions to sdk-doc-comments@openwave.com.