Math functions and most operators require that an array contains only numbers
that are indexed sequentially by integer e.g.,
.escape() |
|
Returns a URL encoding string . |
.unescape() |
|
Returns a URL decoding string . |
.ptr() |
|
Returns an array containing a pointer to the string data as the first item and the length of the data as the second item. |
.import(ptr, len) |
user, integer |
Transfers data from ptr to the string. |
.substr(pos, len) |
integers |
Returns the sub-string starting at pos and include len characters. |
.left(pos) |
integer |
Returns the left part of the string starting at the position. |
.right(pos) |
integer |
Returns the right part of the string starting at the position. |
.mbs2utf() |
string |
Returns a UTF-8 string converted from the multibyte string. |
.utf2mbs() |
string |
Returns a multibyte string converted from the UTF-8 string. |
.numstr() |
|
Returns the number of numerical items in the string, e.g. "12 3.0 0.1e-23". |
.regex(pattern[, func]) |
strings |
Regular expression using Sswater Shi's library. If the optional callback function name is given, the function will be called for each matched case with a string as the first parameter, the start match position as the second, and the end match position as the third; otherwise, regex returns matched strings in an array. |
.replace(substr, rpl) |
string, string |
Returns a copy of the caller with substring substr replaced by rpl. Returns the caller if substr is not found. |
.size() |
string |
Returns the string length. |
.tolower() |
|
Converts the string to lower case and returns a string. |
.toupper() |
|
Converts the string to upper case and returns a string. |
.trim() |
|
Removes leading and trailing spaces and returns a string. |
.tokenize([del, trim]) |
string, boolean |
Breaks the string into an array of tokens. The delimiter is assumed to be space characters (space, tab, etc) if del is not specified. The optional trim parameter may be used to remove space characters on both sides of a token string (true by default). |
csv(a, b, ...) |
any |
Displays the string representations of objects with comma between them
and a new-line character at the end. |
curdir() |
|
Returns the current directory as string. |
curdir([dir]) |
string |
Sets the working directory to dir. |
input(msg) |
string |
Displays the content of msg, waits for user input, and returns the input as string. Your may use the function to write a simple interactive interface, e.g., year=integer(input("Year: ")); if (year > 2000) {...}; ... |
isfile(fname) |
string |
Returns true if fname is a file or false otherwise. |
isdir(dir) |
string |
Returns true if dir is a directory or false otherwise. |
mkdir(dir) |
string |
Makes a new directory. |
print(a, b, ...) |
any |
The same as csv() but without the comma and new-line character. |
scandir(callback, dir) |
string, string |
Scans the directory dir. The callback parameter must be the name of a callback function, which gets two parameters with the first being the path name and the second the file name. |
tmpnam() |
|
Returns a temporal file name. |
open(fname, mode) |
string, boolean |
Opens the file and returns the handle as a user object or null if failed.
If fname is "stdout", "stderr", or "stdin",
the file handle will be assigned to one of those standard C file handles and the
mode argument has no effect. The most frequently used modes include "r", "w", and "a" for reading, writing, and appending text respectively; and "rb" and "wb" for binary reading and writing. |
.eof() |
|
Returns true if the current position of file handle is at the end-of-file; returns false otherwise. |
.flush() |
|
Flushes the output buffer of the file handle that is opened for output. |
ftime(fname[, utc]) |
string, boolean |
Returns the file timestamp as array. Set utc=true to get the timestamp as Universal Time Coordinate. |
.read() |
|
Reads a line of string and returns it. The length of a line
in the file should be less then 8192. |
.read(ptr, n) |
user, integer |
Reads n bytes of binary data from the file to the memory pointed to by ptr.
Returns the actual bytes read. |
.read(type[, n]) |
string, integer |
Reads a binary number. The type parameter may be "char", "uchar", "short", "ushort", "int", "uint", "int64", "float", "double", or "string". If the type is string, its length may be set by the the optional parameter n, which can be zero for reading the whole content from the current position to the end of the document. |
.write(obj) |
any |
Writes the string form of obj to the file. |
.write(ptr, n) |
user, integer |
Writes n bytes of binary data pointed to by ptr to the file. |
.write(num, type) |
number, string |
Writes a binary number to the file. The number will be converted to integer or real according to the type parameter, which may be "char", "uchar", "short", "ushort", "int", "uint", "int64", "float", or "double". |
.seek(offset, flag) |
integer, string |
Moves the file handle by the offset according to the flag, by which "set"
means offset from the start, "end" means from the end, and "cur"
means from the current position. |
.seek(str[, limit]) |
string, integer |
Finds the string in the file and returns the position
at the end of the string if successful; otherwise returns 0. |
.tell() |
|
Returns the current position of the file handle as integer. |
cos(v) |
user, array, integer, real |
Returns real of cos(v) if v is a number. If v is an array, applies the function element-wise
and the array must be indexed sequentially by integer and contain only numbers. If v is a user object, cos must be registered for that type of user object. |
cosh(v) |
user, array, integer, real |
Returns real of cosh(v) if v is a number. See cos(v) requirement for array or user object. |
acos(v) |
user, array, integer, real |
Returns real of acos(v) if v is a number. See cos(v) requirement for array or user object. |
sin(v) |
user, array, integer, real |
Returns real of sin(v) if v is a number. See cos(v) requirement for array or user object. |
sinh(v) |
user, array, integer, real |
Returns real of sinh(v) if v is a number. See cos(v) requirement for array or user object. |
asin(v) |
user, array, integer, real |
Returns real of asin(v) if v is a number. See cos(v) requirement for array or user object. |
tan(v) |
user, array, integer, real |
Returns real of tan(v) if v is a number. See cos(v) requirement for array or user object. |
tanh(v) |
user, array, integer, real |
Returns real of tanh(v) if v is a number. See cos(v) requirement for array or user object. |
atan(v) |
user, array, integer, real |
Returns real of atan(v) if v is a number. See cos(v) requirement for array or user object. |
atan2(a, b) |
user, array, integer, real |
Returns real of atan2(v1, v2) if a and b are numbers. See cos(v) requirement for array or user object. |
sqrt(v) |
user, array, integer, real |
Returns real of sqrt(v) if v is a number. (no check for v < 0) See cos(v) requirement
for array or user object. |
exp(v) |
user, array, integer, real |
Returns real of exp(v) if v is a number. See cos(v) requirement for array or user object. |
log(v) |
user, array, integer, real |
Returns real of log(v) if v is a number. (no check for v <= 0) See cos(v) requirement
for array or user object. |
log10(v) |
user, array, integer, real |
Returns real of log10(v) if v is a number. (no check for v <= 0) See cos(v) requirement
for array or user object. |
ceil(v) |
user, array, integer, real |
Returns real of ceil(v) if v is a number. See cos(v) requirement for array or user object. |
floor(v) |
user, array, integer, real |
Returns real of floor(v) if v is a number. See cos(v) requirement for array or user object. |
abs(v) |
user, array, integer, real |
Returns real of abs(v) if v is a number. See cos(v) requirement for array or user object. |
pow(a, b) |
user, array, integer, real |
Returns real of pow(a, b) if a and b are numbers. See cos(v) requirement for array or user object. |
pi() |
|
Returns constant of pi. |
base64(ptr, n) |
user, integer |
Encodes n bytes in ptr to string. |
base64(str) |
string |
Decodes a base64 string. Returns an array containg a pointer and the number of bytes in the pointer. |
cal2jul(year, month, day,[hour, minute, second]) |
numbers |
Converts Gregorian date to Julian day number and returns the number, of which 1 refers
to 1-Jan-1900. |
jul2cal(jul) |
number |
Converts Julian day number to Gregorian date and returns an array. |
format(fmt, item[,...]) |
string, number or string |
Returns a string of formatted items. The fmt parameter is a C-format string. For example, format( "%02d", 9) gives "09", format("%5.2f", 1.99999) gives "2.00", and format("%d-%02d-%02d %02d:%02d", 2000, 1, 1, 12, 30) gives 2000-01-01 12:00. |
integer(s) |
string/real/real |
Converts string or real to integer and returns a integer. |
real(s) |
string/integer/real |
Converts string or integer to real and returns returns a real. |
string(o) |
any |
Returns the string representative of the object. |
revb(ptr, n, e) |
user, integer, integer |
Reverses bytes oder of the pointer ptr. n is the number of data and e is the datum size in byte. Use the function to convert real or integer from Big-endian to Little-endian and vice versa. |
Operator |
Left Operand |
Right Operand |
Remark |
+ - * / % |
array, number |
array, number |
Returns a real, an integer, or an array of numbers. If
the operand is array, the array must be an integer indexed array containing
only numbers. |
+ |
string |
any |
Appends the right to the left and returns a new string. |
>> |
integer |
integer |
Bit shift of the left to the right by the right value. |
<< |
integer |
integer |
Bit shift of the left to the left by the right value. |
| |
integer |
integer |
Returns the bitwise-or of the two operands. |
& |
integer |
integer |
Returns the bitwise-and of the two operands |
^ |
integer |
integer |
Returns the bitwise-xor of the two operands. |
+= -= *= /= %= |
array, number |
array, number |
The efficient version of +, -, *, /, and %. |
<<= >>= |= &= ^= |
integer |
integer |
The efficient version of <<, >>, |, & and
^. |
== |
any |
any |
Equal comparison. For numbers, returns 1 if the numbers are equal; otherwise
returns 0. For string, comparison is character by character; and a zero-length
string is treated as null. For array, comparison is element-wise. |
!= |
any |
any |
Refer to == |
> >= < <= |
array, number, string |
array, number, string |
Refer to == |
&& || |
any |
any |
Logical and/or operation. For number, non-zero is true; otherwise is false. For string and array, zero-length means false; otherwise means true. The null is false. |
: |
any |
any |
Returns an array when used independently and specifies a range when used for getting/setting string, array, or user object. |
= |
variable name |
any |
Assign the right to the left. |