Collected WML script standard function library 1th/3 page _WML Tutorial

Source: Internet
Author: User
Tags abs min parse error random seed
This section discusses the standard WML script function library.
6.1 WML Script Rules
These standard function libraries provide a mechanism to extend the WML script language, which must follow the rules of WML script.
Supported data formats
The following WML script format is used in the definition of the program so that it can record the format of program parameters and rotation values.
Boolean
Integer
Float
String
Invalid
In addition, if the integer and floating-point value formats are acceptable, you can use number to record the parameter format, if the format used is the supported format, you can use any to record.
Data format Conversion
The function library program has the same processing error as the WML script language.
The invalid program parameter produces a invalid return value.
The parameters of the program cannot be converted to the required parameter format, then a invalid return value is generated.
A program-related error is returned with an appropriate error code, and the value depends on how each program is defined.
6.2 Lang Function Library
Name: Lang
Description: This function library contains programs that are closely related to the core of the WML script language.
Abs
Program: ABS (Value)
Note: The absolute value of the number given by the postback.
If the given number is an integer, the integer is returned.
If the given number is a float, the floating-point numbers are returned.
Parameter: value= number.
Return value: Number or invalid.
Exceptional condition: var a =-3;
var b =lang.abs (a);//b=3
Min
Example: var a =-3
var B = Lang.abs (a);
var c = lang.min (A.B);
var d = lang.min (45, 76.3);//d=45 (Ingteger)
var e = lang.min (45, 76.3);//e=45 (Ingteger)
Max
Program: Max (value1,value2)
Note: The return value given by the two number of large value, the return value in the format and the value of the selected values and format the same, it is selected in the following way:
The integer and floating-point conversion rules in the WML script operator data format can be used to confirm the data format in order to perform the comparison action.
Parameters: value1 = number
value2 = number
Postback value: Number or invalid
Exception condition: None
Example: Var a =-3;
var b =lang.abs (a);//b=3
var c = lang.min (A.B);
var d = lang.min (45, 76.3);//d=45 (Ingteger)
var e = lang.min (45, 76.3);//e=45 (float)
parseint
Program: parseint (value)
Note: Return the integer value defined by the string value, and the valid integer syntax is defined by the WML script numeric string grammar or near-value integer, which is the following additional parsing rule:
The first character is not preceded by A +,-or decimal digit, and the interpreter ends.
Result: The parsed string is converted to an integer value.
Example: var i =lang.parseint ("1234"); i=1234
var j =lang.parseint ("M/S"); j=100
Parsefloat
Program: parsefloat (value)
Note: Return the floating-point value defined by the string value, the legal floating-point number syntax is defined by the WML script numeric string grammar or the near-value integer name, and the following are the additional parsing rules:
The first character cannot be parsed into a floating-point expression, parsing ends.
End: The parsed string rotation is replaced by a floating-point number.
Parameters: value= String
Return value: Floating-point number or invalid
Exception: Parse error returns to invalid
Example: Var a =lang.parsefloat ("123.7 Hz"); a=123.7
var b =lang.parsefloat ("7.34e2 Hz"); B=7.34e2
var c =lang.parsefloat ("70.0e-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
Isint
Program: Isint (value)
Note: If each of the predefined value values can be converted to an integer by using parseint (value), the Ture value is returned, or false is returned.
Parameters: value= arbitrary values
Return value: Boolean value or invalid
Exception condition: None
Example: Var a=lang.inint ("-123"); Ture
var a =lang.minint ("123.33"); Ture
var a =lang.minint ("string"); False
var a =lang.minint ("#123"); False
var a =lang.minint ("invalid"); Invalid
Isfloat
Program: Isfloat (value)
Note: If each of the predefined value values can be converted to an integer by using parseint (value), the Ture value is returned, or false is returned.
Parameters: value= arbitrary values
Return value: Boolean value or invalid
Exception condition: None
Example: Var a=lang.inint ("-123"); Ture
var a =lang.minint ("123.33"); Ture
var a =lang.minint ("string"); False
var a =lang.minint ("#123"); False
var a =lang.minint ("invalid"); Invalid
Maxint
Program: Maxint ()
Description: Returns the largest integer value.
Parameters: None
Postback value: Integer 2147483647
Exception condition: None
Example: Var a =lang.minint ();
Minint
Program: Minint ()
Description: Returns the smallest integer value
Parameters: None
Postback value: integer-2147483647
Exception condition: None
Example: Var a =lang.minint ();
Float
Program: Float ()
Note: If there is support for floating-point numbers, return ture, no word returns false.
Parameters: None
Postback Value: Boolean value
Exception condition: None
Example: var floatssupported = Lang.float ();
Exit
Program: Exit (Value)
Description: Ends the interpretation of the WML script bit code and then returns to the control of the calling WML script interpreter, returning the specified value, which you can use to perform the end of the general program, and the execution of the WML script must stop.
Parameters: valre= arbitrary values
Return value: None, this program end interpretation
Exception condition: None
Example: Lang.exit ("Value:" + myval);//returns a string
Lang,exit (invalid);//Returns invalid
Abort
Program: Abort (errordescription)
Note: Abort the interpretation of the WML script bit code and return to the control of the calling WML script interpreter and back to ErrorDescription, you can use this program to perform an abnormal abort, the caller detects a serious error, and the WML script executes and interrupts.
If the errordescription format is invalid, the string invalid is used in place of errordescription.
Parameters: ErrorDescription = string
Return value: None, this program end interpretation
Exception condition: None
Example: Lang.abort ("Error:" + errval); Error Value string
Radndom
Program: Random (value)
Note: Return an integer value of a positive number, that is, to be greater than or equal to zero, but must be less than the given value, and the return value is randomly selected by near normal distribution.
Parameters: value= integers
Postback value: integer or invalid
Exception: If value equals 0, the program will return 0
If value is less than 0, the program invalid
Example: var a = 10;
var b =lang.random (5.1) *a;//b=0..50
var c = lang.random ("string"); C=invalid
Reed
Program: Seed (Alue)
Description: Initialize a random number sequence and return an empty string
If value is 0 or a positive integer, the given value is used to initialize, whereas the value that is randomly initialized is used.
If value is a floating-point number, the exact integer value is computed using Float.int () first.
Parameters: value= integers
Postback value: string or invalid]
Exception condition: None
Example: Var a =lang.reed (123);//A= ""
var b =lang.random (20); b=0..20
var c = lang.seed ("seed"); C=invalid (random seed//left unchanged)
CharacterSet
Program: CharacterSet ()
Note: Back up the word set supported by the WML script interpreter, and the postback is just an integer used to record the MIB enum value set by the IANA, which can only represent all of the word sets.
Parameters: None
Postback value: integer
Exception condition: None
Example: Var charset = Lang.characterset (); CharSet = 4 for Latinl
Current 1/3 page 123 Next read the full text

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.