O'Reilly logo

Learning WML, and WMLScript by Martin Frost

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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:

function function-name (parameter-list)
{
    body
}

or:

extern function function-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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required