Chapter 13. WMLScript Functions
You’ve now seen nearly all the elements that make up WMLScript, but one thing that hasn’t yet been properly covered is how you wrap these bits up into functions that can be called from WML.
That process is covered in this chapter, together with how you can put commonly used WMLScript functions into a single library and call these from different places.
Function Declarations
You’ve already seen examples of a function declaration—in Chapter 9, and Chapter 10—but you haven’t seen all the details.
Functions are declared after any pragmas (more on pragmas in Chapter 14). A function declaration looks like either:
functionfunction-name (parameter-list)
{body
}
or:
extern functionfunction-name (parameter-list)
{body
}
If the function is declared
extern
, it’s available to be called
from WML or from other WMLScript functions not declared in the same
file. If it’s declared without the extern
keyword, it can be called only by other WMLScript code in the same
source file.
The function name follows the same rules as WMLScript variable names: anything that is a legal variable name is a valid function name. In addition, you can use the same name for a variable and a function, since WMLScript keeps separate namespaces for each.
The function body is simply a list of WMLScript statements.
The
parameter-list
is a list of the names of each of the parameters to the function. These names follow the same rules as variable names. This is not surprising, since in the function body ...
Get Learning WML, and WMLScript now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.