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:
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.
errorDescription = String
None (this function aborts the interpretation)
Lang.abort("Error: " + errVal); //Error value is a string
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.
value = Number
Number or invalid
var a = -3;
var b = Lang.abs(a); //b = 3
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.
Integer
var charset = Lang.characterSet();
// charset = 4 for latin1
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.
value = Any
None (this function ends the interpretation)
Lang.exit("Value: " + myVal); // Returns a string
Lang.exit(invalid); // Returns invalid
lang.float()
Returns true if floating-points are supported, and false if not.
Boolean
var floatsSupported = Lang.float();
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.
value = Any
Boolean or invalid
If the system does not support floating-point operations, an invalid value is returned.
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
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.
value = Any
Boolean or invalid
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
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:
WMLScript 1.1 operator data type conversion rules for integers and floating-points must be used to specify the data type (integer or floating-point) for comparison.
Compare the numbers to select the larger one.
If the values are equal, the first value is selected.
value1 = Number
value2 = Number
Number or invalid
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
lang.maxInt()
Returns the maximum integer value.
Integer 2147483647
var a = Lang.maxInt();
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:
WMLScript 1.1 operator data type conversion rules for integers and floating-points must be used to specify the data type (integer or floating-point) for comparison.
Compare the numbers to select the smaller one.
If the values are equal, the first value is selected.
value1 = Number
value2 = Number
Number or invalid
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)
lang.minInt()
Returns the minimum integer value.
Integer -2147483648
var a = Lang.minInt();
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:
Parsing ends when the first character is encountered that cannot be parsed as being part of the floating-point representation.
The result is the parsed string converted to a floating-point value.
value = String
Floating-point or invalid
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.
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
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:
Parsing ends when the first character is encountered that is not a leading `+' or `-' or a decimal digit.
The result is the parsed string converted to an integer value.
value = String
Integer or invalid
In case of a parsing error, an invalid value is returned.
var i = Lang.parseInt ("1234"); // i = 1234
var j = Lang.parseInt (" 100 m/s"); // j = 100
var k = Lang.parseInt("The larch") // k = invalid
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.
value = Integer
Integer or invalid
If value is equal to zero (0), the function returns zero.
If value is less than zero (0), the function returns invalid.
var a = 10;
var b = Lang.random(5.1)*a; // b = 0..50
var c = Lang.random("string"); // c = invalid
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.
value = Integer
String or invalid
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)