WMLScript Reference

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

Current chapter: Chapter 8 - Libraries
Section 25 out of 34 total sections , Section 3 out of 9 sections in this chapter


Lang Library

The Lang library contains a set of functions that are closely related to the
WMLScript 1.1 language core. Included in this section are the following function calls:

Function call 

abort 

abs 

characterSet 

exit 

float 

isFloat 

isInt 

max 

maxInt 

min 

minInt 

parseFloat 

parseInt 

random 

seed 



abort

lang.abort(errorDescription)  

Aborts the interpretation of the WMLScript 1.1 bytecode and returns the control to the caller of the WMLScript 1.1 interpreter with the return errorDescription. This function can be used to perform an abnormal exit in cases where the execution of the WMLScript 1.1 should be discontinued because of serious errors detected by the calling function. If the type of the errorDescription is invalid, the string "invalid" is used instead.


Parameters

errorDescription = String


Return Value

None (this function aborts the interpretation)


Examples

Lang.abort("Error: " + errVal);  //Error value is a string  


abs

lang.abs(value)  

Returns the absolute value of the given number. If the given number is of type integer, an integer value is returned. If the given number is of type floating-point, a floating-point value is returned.


Parameters

value = Number


Return Value

Number or invalid


Examples

var a = -3;  
 
var b = Lang.abs(a);        //b = 3  


characterSet

lang.characterSet()  

Returns the character set supported by the WMLScript 1.1 interpreter. The return value is an integer that denotes a MIBEnum value assigned by the Internet Assigned Numbers Authority (IANA) for all character sets.


Return Value

Integer


Examples

var charset = Lang.characterSet();
    // charset = 4 for
latin1  



exit

lang.exit(value)  

Ends the interpretation of WMLScript 1.1 bytecode and returns the control to the caller of the WMLScript 1.1 interpreter with the given return value. This function can be used to perform a normal exit from a function in cases where the execution of the WMLScript 1.1 bytecode should be discontinued.


Parameters

value = Any


Return Value

None (this function ends the interpretation)


Examples

Lang.exit("Value: " + myVal);       // Returns a string  
Lang.exit(invalid);                 // Returns invalid  


float

lang.float()  

Returns true if floating-points are supported, and false if not.


Return Value

Boolean


Examples

var floatsSupported = Lang.float();  


isFloat

lang.isFloat(value)  

Returns a boolean value that is true if the given value can be converted into a floating-point number using parseFloat(value). Otherwise false is returned.


Parameters

value = Any


Return Value

Boolean or invalid


Exceptions

If the system does not support floating-point operations, an invalid value is returned.


Examples

var a = Lang.isFloat (" -123");     // true  
var b = Lang.isFloat (" 123.33");   // true  
var c = Lang.isFloat ("string");    // false  
var d = Lang.isFloat ("#123.33");   // false  
var e = Lang.isFloat (invalid);     // invalid  


isInt

lang.isInt(value)  

Returns a boolean value that is true if the given value can be converted into an integer by using parseInt(value). Otherwise false is returned.


Parameters

value = Any


Return Value

Boolean or invalid


Examples

var a = Lang.isInt(" -123");        // true  
var b = Lang.isInt(" 123.33");      // true  
var c = Lang.isInt("string");       // false  
var d = Lang.isInt("#123");         // false  
var e = Lang.isInt(invalid);        // invalid  


max

lang.max(value1, value2);  

Returns the maximum value of the given two numbers. The value and type returned is the same as the value and type of the selected number. The selection is done in the following way:


Parameters

value1 = Number

value2 = Number


Return Value

Number or invalid


Examples

var a = -3;  
var b = Lang.abs(a);  
var c = Lang.max(a, b);            // c = -3  
var d = Lang.max(45.5, 76);        // d = 76(integer)  
var e = Lang.max(45.0, 45);        // e = 45.0  


maxInt

lang.maxInt()  

Returns the maximum integer value.


Return Value

Integer 2147483647


Examples

var a = Lang.maxInt();  


min

lang.min(value1, value2)  

Returns the minimum value of the given two numbers. The value and type returned is the same as the value and type of the selected number. The selection is done in the following way:


Parameters

value1 = Number

value2 = Number


Return Value

Number or invalid


Examples

var a = -3;  
var b = Lang.abs(a);  
var c = Lang.min(a, b);            // c = -3  
var d = Lang.min(45, 76.3);        // d = 45 (integer)  
var e = Lang.min(45, 45.0);        // e = 45 (integer)  


minInt

lang.minInt()  

Returns the minimum integer value.


Return Value

Integer -2147483648


Examples

var a = Lang.minInt();  


parseFloat

lang.parseFloat(value)  

Returns a floating-point value defined by the string value. The legal floating-point syntax is specified by the WMLScript 1.1 numeric string grammar for decimal floating-point literals with the following additional parsing rule:

The result is the parsed string converted to a floating-point value.


Parameters

value = String


Return Value

Floating-point or invalid


Exceptions

In case of a parsing error, an invalid value is returned.

If the system does not support floating-point operations, an invalid value is returned.


Examples

var a = Lang.parseFloat("123.4");          // a = 123.4  
var b = Lang.parseFloat(" +7.34e2 Hz")     // b = 7.34e2  
var c = Lang.parseFloat(" 70e-2 F");       // c = 70.0e-2  
var d = Lang.parseFloat("-.1 C");          // d = -0.1  
var e = Lang.parseFloat(" 100 ");          // e = 100.0  
var f = Lang.parseFloat("Number: 5.5");    // f = invalid  
var g = Lang.parseFloat("7.3e meters");    // g = invalid  
var h = Lang.parseFloat("7.3e- m/s");      // h = invalid  


parseInt

lang.parseInt(value)  

Returns an integer value defined by the string value. The legal integer syntax is specified by the WMLScript 1.1 numeric string grammar for decimal integer literals with the following additional parsing rule:

The result is the parsed string converted to an integer value.


Parameters

value = String


Return Value

Integer or invalid


Exceptions

In case of a parsing error, an invalid value is returned.


Examples

var i = Lang.parseInt ("1234");            // i = 1234  
var j = Lang.parseInt (" 100 m/s");        // j = 100  
var k = Lang.parseInt("The larch")         // k = invalid  


random

lang.random(value)  

Returns an integer value a with positive value that is greater than or equal to 0 but less than or equal to the given value. The return value is chosen randomly or pseudo-randomly with approximately uniform distribution over that range, using an implementation-dependent algorithm or strategy.

If the value is of type floating-point, Float.int() is first used to calculate the actual integer value.


Parameters

value = Integer


Return Value

Integer or invalid


Exceptions

If value is equal to zero (0), the function returns zero.

If value is less than zero (0), the function returns invalid.


Examples

var a = 10;  
var b = Lang.random(5.1)*a;          // b = 0..50  
var c = Lang.random("string");       // c = invalid  


seed

lang.seed(value)  

Initializes the pseudo-random number sequence and returns an empty string. If the value is zero or a positive integer then the given value is used for initialization, otherwise a random, system-dependent initialization value is used.

If the value is of type floating-point, Float.int() is first used to calculate the actual integer value.


Parameters

value = Integer


Return Value

String or invalid


Examples

var a = Lang.seed(123);           // a = ""  
var b = Lang.random(20);          // b = 0..20  
var c = Lang.seed("seed");  
    // c = invalid (random seed left unchanged)  

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


Part Number DKWS-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.