Embedded Systems October 2000 Vol13_11

Issue link:

Contents of this Issue


Page 55 of 181

WMLScript functions follow specific rules and have rigid constraints, such as always returning a value, passing parameters by value only, and not allowing function nesting. WMLScript adds programming lan- guage con tructs such as if-then state- ments. WML is weakly typed, and it's easy to lose track of variables between native WML and WMLScript. WMLScrip t looks much more like LISTING 2 WMlScript function formats II for externaLLy accessibLe functions extern function FunctionLO(params) { BLockOfCode; } , . II for LocaL caLLs onLy function FunctionLO(params) { BLockOfCode; }. , a conve ntional programming lan- guage than WML. Since WML is a sta- tic language, some se ri ous issu es come up, such as use r data input validity testing, target device resource access, and local message generation to users. How does WML know if a user ente red a name instead of a phone numbe r? What if the use r ente rs something wrong and an error message must be displayed to alert the use r? Does this mean that a new card must be accessed through a WAP proxy and Web server just to get a sim- ple e rro r mes 'age? WMLScript addresses these problems and offe r enough high level language features to solve them. WMLScrip t is fun ction-orie nted . There is no call to mainO, as in a C program. All functions are stored in compilation units and stored on a se r'ver for executio n. The LISTING 3 WMLlWMLScript variable interaction

Num Is: $(t-U'I)

II This function is in num.I.I11Ls extern function GetNum() { var lll.lrVer = 5; WMLBrowser. setVar( "NUll", number); WMLBrowser .go("num.I.I11L1#cardZ); } , . S4 OOOBER 2000 El11bedded Systel11s Progral11l11ing fo rms of WMLScript fl.ln ctions are shown in Listing 2. vVMLScript functions fo llow pecif- ic rul es and have rigid constrain ts, such as always returning a value, pass- ing parametel-s by value only, and not allowing function nesting. WMLScript supports two types of functions: exter- nal and in tern a!. External functions are declared when the function is used outside of its compilation unit. This is like making a class member public in C++. ]f a function is used strictly Witll- in its local compilation unit, t11en the function is declared normally and is not visible to the outside world . A block of code is like a block of code in C or C++. Listing 3 shows how to link WMLScript functions to a WML page. This example uses the WMLScript library fun ction setVarO to set a vari- able in a WML program. The example displays the number 5 on the client's display. The functi on GetNumO is called from wiiliin the element in Cardl. The vVML program stops exe- cUlion, GetNum() is referenced and in terpreted , and the results are returned in the WML variable NUM in Card2. The WMLScript fun ction uses

Articles in this issue

Archives of this issue

view archives of EETimes - Embedded Systems October 2000 Vol13_11