1 # <a id="library-reference"></a> Library Reference
3 ## <a id="global-functions"></a> Global functions
6 --------------------------------|-----------------------
7 regex(pattern, text) | Returns true if the regex pattern matches the text, false otherwise.
8 match(pattern, text) | Returns true if the wildcard pattern matches the text, false otherwise.
9 len(value) | Returns the length of the value, i.e. the number of elements for an array or dictionary, or the length of the string in bytes.
10 union(array, array, ...) | Returns an array containing all unique elements from the specified arrays.
11 intersection(array, array, ...) | Returns an array containing all unique elements which are common to all specified arrays.
12 keys(dict) | Returns an array containing the dictionary's keys.
13 string(value) | Converts the value to a string.
14 number(value) | Converts the value to a number.
15 bool(value) | Converts the value to a bool.
16 random() | Returns a random value between 0 and RAND_MAX (as defined in stdlib.h).
17 log(value) | Writes a message to the log. Non-string values are converted to a JSON string.
18 log(severity, facility, value) | Writes a message to the log. `severity` can be one of `LogDebug`, `LogNotice`, `LogInformation`, `LogWarning`, and `LogCritical`. Non-string values are converted to a JSON string.
19 exit(integer) | Terminates the application.
21 ## <a id="math-object"></a> Math object
23 The global `Math` object can be used to access a number of mathematical constants
26 ### <a id="math-e"></a> Math.E
30 ### <a id="math-ln2"></a> Math.LN2
32 Natural logarithm of 2.
34 ### <a id="math-ln10"></a> Math.LN10
36 Natural logarithm of 10.
38 ### <a id="math-log2e"></a> Math.LOG2E
40 Base 2 logarithm of E.
42 ### <a id="math-pi"></a> Math.PI
44 The mathematical constant Pi.
46 ### <a id="math-sqrt1_2"></a> Math.SQRT1_2
50 ### <a id="math-sqrt2"></a> Math.SQRT2
54 ### <a id="math-abs"></a> Math.abs
60 Returns the absolute value of `x`.
62 ### <a id="math-acos"></a> Math.acos
68 Returns the arccosine of `x`.
70 ### <a id="math-asin"></a> Math.asin
76 Returns the arcsine of `x`.
78 ### <a id="math-atan"></a> Math.atan
84 Returns the arctangent of `x`.
86 ### <a id="math-atan2"></a> Math.atan2
92 Returns the arctangent of the quotient of `y` and `x`.
94 ### <a id="math-ceil"></a> Math.ceil
100 Returns the smallest integer value not less than `x`.
102 ### <a id="math-cos"></a> Math.cos
108 Returns the cosine of `x`.
110 ### <a id="math-exp"></a> Math.exp
116 Returns E raised to the `x`th power.
118 ### <a id="math-floor"></a> Math.floor
124 Returns the largest integer value not greater than `x`.
126 ### <a id="math-isinf"></a> Math.isinf
132 Returns whether `x` is infinite.
134 ### <a id="math-isnan"></a> Math.isnan
140 Returns whether `x` is NaN (not-a-number).
142 ### <a id="math-log"></a> Math.log
148 Returns the natural logarithm of `x`.
150 ### <a id="math-max"></a> Math.max
156 Returns the largest argument. A variable number of arguments can be specified.
157 If no arguments are given -Infinity is returned.
159 ### <a id="math-min"></a> Math.min
165 Returns the smallest argument. A variable number of arguments can be specified.
166 If no arguments are given +Infinity is returned.
168 ### <a id="math-pow"></a> Math.pow
174 Returns `x` raised to the `y`th power.
176 ### <a id="math-random"></a> Math.random
182 Returns a pseudo-random number between 0 and 1.
184 ### <a id="math-round"></a> Math.round
190 Returns `x` rounded to the nearest integer value.
192 ### <a id="math-sign"></a> Math.sign
198 Returns -1 if `x` is negative, 1 if `x` is positive
201 ### <a id="math-sin"></a> Math.sin
207 Returns the sine of `x`.
209 ### <a id="math-sqrt"></a> Math.sqrt
215 Returns the square root of `x`.
217 ### <a id="math-tan"></a> Math.tan
223 Returns the tangent of `x`.
225 ## <a id="number-type"></a> Number type
227 ### <a id="number-to_string"></a> Number#to_string
231 function to_string();
233 The `to_string` method returns a string representation of the number.
238 example.to_string() /* Returns "7" */
240 ## <a id="boolean-type"></a> Boolean type
242 ### <a id="boolean-to_string"></a> Boolean#to_string
246 function to_string();
248 The `to_string` method returns a string representation of the boolean value.
253 example.to_string() /* Returns "true" */
255 ## <a id="string-type"></a> String type
257 ### <a id="string-find"></a> String#find
261 function find(str, start);
263 Returns the zero-based index at which the string `str` was found in the string. If the string
264 was not found -1 is returned. `start` specifies the zero-based index at which `find` should
265 start looking for the string (defaults to 0 when not specified).
269 "Hello World".find("World") /* Returns 6 */
271 ### <a id="string-len"></a> String#len
277 Returns the length of the string in bytes. Note that depending on the encoding type of the string
278 this is not necessarily the number of characters.
282 "Hello World".len() /* Returns 11 */
284 ### <a id="string-lower"></a> String#lower
290 Returns a copy of the string with all of its characters converted to lower-case.
294 "Hello World".lower() /* Returns "hello world" */
296 ### <a id="string-upper"></a> String#upper
302 Returns a copy of the string with all of its characters converted to upper-case.
306 "Hello World".upper() /* Returns "HELLO WORLD" */
308 ### <a id="string-replace"></a> String#replace
312 function replace(search, replacement);
314 Returns a copy of the string with all occurences of the string specified in `search` replaced
315 with the string specified in `replacement`.
317 ### <a id="string-split"></a> String#split
321 function split(delimiters);
323 Splits a string into individual parts and returns them as an array. The `delimiters` argument
324 specifies the characters which should be used as delimiters between parts.
328 "x-7,y".split("-,") /* Returns [ "x", "7", "y" ] */
330 ### <a id="string-substr"></a> String#substr
334 function substr(start, len);
336 Returns a part of a string. The `start` argument specifies the zero-based index at which the part begins.
337 The optional `len` argument specifies the length of the part ("until the end of the string" if omitted).
341 "Hello World".substr(6) /* Returns "World" */
343 ### <a id="string-to_string"></a> String#to_string
347 function to_string();
349 Returns a copy of the string.
351 ## <a id="array-type"></a> Array type
353 ### <a id="array-add"></a> Array#add
361 ### <a id="array-clear"></a> Array#clear
369 ### <a id="array-clone"></a> Array#clone
375 ### <a id="array-contains"></a> Array#contains
379 function contains(value);
383 ### <a id="array-len"></a> Array#len
391 ### <a id="array-remove"></a> Array#remove
395 function remove(index);
399 ### <a id="array-set"></a> Array#set
403 function set(index, value);
407 ### <a id="array-sort"></a> Array#sort
411 function sort(less_cmp);
413 Returns a copy of the array where all items are sorted. The items are
414 compared using the `<` (less-than) operator. A custom comparator function
415 can be specified with the `less_cmp` argument.
417 ## <a id="dictionary-type"></a> Dictionary type
419 ### <a id="dictionary-clone"></a> Dictionary#clone
427 ### <a id="dictionary-contains"></a> Dictionary#contains
431 function contains(key);
435 ### <a id="dictionary-len"></a> Dictionary#len
443 ### <a id="dictionary-remove"></a> Dictionary#remove
447 function remove(key);
451 ### <a id="dictionary-set"></a> Dictionary#set
455 function set(key, value);
459 ## <a id="scriptfunction-type"></a> Function type
461 ### <a id="scriptfunction-call"></a> Function#call
465 function call(thisArg, ...);
467 Invokes the function using an alternative `this` scope. The `thisArg` argument specifies the `this`
468 scope for the function. All other arguments are passed directly to the function.
472 function set_x(val) {
478 set_x.call(dict, 7) /* Invokes set_x using `dict` as `this` */
480 ### <a id="scriptfunction-callv"></a> Function#callv
484 function callv(thisArg, args);
486 Invokes the function using an alternative `this` scope. The `thisArg` argument specifies the `this`
487 scope for the function. The items in the `args` array are passed to the function as individual arguments.
491 function set_x(val) {
499 set_x.callv(dict, args) /* Invokes set_x using `dict` as `this` */