June 17, 2000 - Compilation Units and Pragmas
June 17, 2000 Compilation Units and Pragmas Tips: June 2000
Yehuda Shiran, Ph.D.
|
The use url pragma
specifies the location (URL) of the external WMLScript resource and gives it a local name. This name can then be used inside a function declarations to make external function calls. Let's examine the following example:
use url DocJS "https://www.docjavascript.com/mylibs/mywmlscript"
function divide(nom, denom) {
if (denominator == 0) return invalid;
return DocJS#mydiv(nom, denom);
}
The sequence of operations that take place here is fairly intuitive. The use url pragma
specifies a URL to a WMLScript compilation unit, https://www.docjavascript.com/mylibs/mywmlscript
. If the file extension is omitted (as above), the user agent will look for the extension .wmlsc
, i.e. it will look for https://www.docjavascript.com/mylibs/mywmlscript.wmlsc
. As we explained in Column 61Introducing WML and WMLScript, WMLScript scripts are stored under .wmls
file extension and their compilation results are stored under .wmlsc
.
Once the file is found, the function call DocJS#mydiv()
triggers the loading of the external compilation unit, https://www.docjavascript.com/mylibs/mywmlscript.wmlsc
. Upon successful loading of the external resource, its content is verified to have the definition of the mydiv()
function, and it is actually executed with the calling parameters, mydiv(nom, denom)
. The use url pragma
has its own name space for local names, but they must be unique within the same compilation unit.
For more on WMLScript, go to WMLScript Primer.