-
Notifications
You must be signed in to change notification settings - Fork 0
Wi Standard Library Reference
Every language has a standard library, Wi has one too. This page is a reference to it.
| Library | Description | Constants | Functions |
|---|---|---|---|
base |
Built-in global functions |
print, input, load_foreign, is_main, exit, error, assert, try, type, is_real, is_null, is_bool, is_string, is_array, is_map, is_foreign, is_function, is_object, is_userdata, is_falsy, to_real, to_bool, to_string, has_field, fields
|
|
os |
OS utility functions |
clock, time, get_env, args
|
|
math |
Math constants and functions |
E, PI, HUGE
|
abs, acos, asin, atan, ceil, cos, deg, exp, floor, mod, log, log10, ln, max, min, pow, rad, random, round, sin, sqrt, tan
|
utf8 |
UTF-8 aware string functions |
len, at
|
|
string |
String manipulation functions |
sub, upper, lower, trim, has, starts_with, ends_with, replace, split, reverse
|
|
array |
Array manipulation functions |
copy, clear, capacity, count, equals, reverse, reversed, add, has, remove, remove_at, pop, concat, slice, each
|
|
map |
Map manipulation functions |
copy, clear, capacity, count, equals, keys, values, has, get_or_default, remove, each
|
Print values to the standard output
Parameters:
-
any ...args: Values to print
Read a line from standard input
Returns: string read line, or null on end of input
Load foreign library
Parameters:
-
string path: Foreign library path (relative toforeignfolder)
Check if current script is the main one, i.e. the script used to start program execution
Returns: bool
Request the state to stop execution
Raise a runtime error
Parameters:
-
string message: Error message
Raise a runtime error if the value is falsy
Parameters:
-
any value: Value to check -
string message: Error message
Returns: bool
Safely execute an error-prone function
Parameters:
-
function fn: Function to execute -
any ...args: Function arguments
Returns: object with fields ok, value, and error
Get value type
Parameters:
-
any value: Value
Returns: string value type
Check if the value is a real value
Parameters:
-
any value: Value to check
Returns: bool
Check if the value is a null value
Parameters:
-
any value: Value to check
Returns: bool
Check if the value is a bool value
Parameters:
-
any value: Value to check
Returns: bool
Check if the value is a string
Parameters:
-
any value: Value to check
Returns: bool
Check if the value is an array
Parameters:
-
any value: Value to check
Returns: bool
Check if the value is a map
Parameters:
-
any value: Value to check
Returns: bool
Check if the value is a foreign function
Parameters:
-
any value: Value to check
Returns: bool
Check if the value is a function
Parameters:
-
any value: Value to check
Returns: bool
Check if the value is an object
Parameters:
-
any value: Value to check
Returns: bool
Check if the value is a userdata
Parameters:
-
any value: Value to check
Returns: bool
Check if the value is falsy
Parameters:
-
any value: Value to check
Returns: bool
Try and convert a value to a real value
Parameters:
-
any value: Value to convert
Returns: real converted value
Try and convert a value to a bool value
Parameters:
-
any value: Value to convert
Returns: bool converted value
Try and convert a value to a string
Parameters:
-
any value: Value to convert
Returns: string converted value
Check if an object has a field
Parameters:
-
object obj: Object -
string field: Field name
Returns: bool
Get an object's fields as a map
Parameters:
-
object obj: Object
Returns: map object fields
Get the number of CPU seconds elapsed since the program started
Returns: real
Get the current Unix timestamp (seconds since epoch)
Returns: real
Get the value of an environment variable
Parameters:
-
string name: Environment variable name
Returns: string value, or null if not set
Get the command line arguments passed to the script after the --
Returns: array of string arguments
Value: 2.7182818284590452354
Value: 3.14159265358979323846
Value: inf
Get the absolute value of a number
Parameters:
-
real x: Value
Returns: real
Get the arc cosine of a number, in radians
Parameters:
-
real x: Value
Returns: real
Get the arc sine of a number, in radians
Parameters:
-
real x: Value
Returns: real
Get the arc tangent of a number, in radians
Parameters:
-
real x: Value
Returns: real
Round a number up to the nearest integer
Parameters:
-
real x: Value
Returns: real
Get the cosine of an angle given in radians
Parameters:
-
real x: Angle, in radians
Returns: real
Convert an angle from radians to degrees
Parameters:
-
real x: Angle, in radians
Returns: real angle, in degrees
Get e raised to the given power
Parameters:
-
real x: Exponent
Returns: real
Round a number down to the nearest integer
Parameters:
-
real x: Value
Returns: real
Get the floating-point remainder of a / b
Parameters:
-
real a: Dividend -
real b: Divisor
Returns: real
Get the logarithm of a value with the given base
Parameters:
-
real value: Value -
real base: Logarithm base
Returns: real
Get the base-10 logarithm of a value
Parameters:
-
real x: Value
Returns: real
Get the natural logarithm (base e) of a value
Parameters:
-
real x: Value
Returns: real
Get the largest of the given values
Parameters:
-
real ...values: Values to compare (at least one)
Returns: real
Get the smallest of the given values
Parameters:
-
real ...values: Values to compare (at least one)
Returns: real
Raise a number to the given power
Parameters:
-
real base: Base -
real exp: Exponent
Returns: real
Convert an angle from degrees to radians
Parameters:
-
real x: Angle, in degrees
Returns: real angle, in radians
Get a pseudo-random real number in the range [0, 1)
Returns: real
Round a number to the nearest integer
Parameters:
-
real x: Value
Returns: real
Get the sine of an angle given in radians
Parameters:
-
real x: Angle, in radians
Returns: real
Get the square root of a number
Parameters:
-
real x: Value
Returns: real
Get the tangent of an angle given in radians
Parameters:
-
real x: Angle, in radians
Returns: real
Get the number of the UTF-8 codepoints in a string
Parameters:
-
string str: String
Returns: real
Get the UTF-8 codepoint at the given index
Parameters:
-
string str: String -
real index: Codepoint index
Returns: string single codepoint
Get a substring
Parameters:
-
string str: String -
real start: Start index, inclusive -
real end: End index, exclusive
Returns: string substring from start to end
Convert a string to uppercase
Parameters:
-
string str: String
Returns: string
Convert a string to lowercase
Parameters:
-
string str: String
Returns: string
Remove leading and trailing whitespace from a string
Parameters:
-
string str: String
Returns: string
Check if a string contains a substring
Parameters:
-
string str: String -
string target: Substring to search for
Returns: bool
Check if a string starts with a prefix
Parameters:
-
string str: String -
string prefix: Prefix to check for
Returns: bool
Check if a string ends with a suffix
Parameters:
-
string str: String -
string suffix: Suffix to check for
Returns: bool
Replace all occurrences of a substring with another string
Parameters:
-
string str: String -
string old: Substring to replace -
string new: Replacement string
Returns: string
Split a string by a separator
Parameters:
-
string str: String -
string sep: Separator
Returns: array of string parts
Reverse a string
Parameters:
-
string str: String
Returns: string
Create a shallow copy of an array
Parameters:
-
array arr: Array
Returns: array copy
Remove all the items from an array
Parameters:
-
array arr: Array
Get the current item capacity of an array
Parameters:
-
array arr: Array
Returns: real
Get the number of the items in an array
Parameters:
-
array arr: Array
Returns: real
Check if two arrays have the same length and equal items in the same order
Parameters:
-
array a: First array -
array b: Second array
Returns: bool
Reverse an array
Parameters:
-
array arr: Array
Returns: array the same array, reversed
Get a new array with the items in reverse order
Parameters:
-
array arr: Array
Returns: array new reversed array
Add a value to the end of an array
Parameters:
-
array arr: Array -
any value: Value to add
Returns: any the added value
Check if an array contains a value
Parameters:
-
array arr: Array -
any value: Value to search for
Returns: bool
Remove the first occurrence of a value from an array
Parameters:
-
array arr: Array -
any value: Value to remove
Returns: bool whether a value was found and removed
Remove the item at the given index
Parameters:
-
array arr: Array -
real index: Index to remove
Returns: any the removed value
Remove the last item of an array
Parameters:
-
array arr: Array
Returns: any the removed value
Concatenate multiple arrays into a new array
Parameters:
-
array ...arrays: Arrays to concatenate
Returns: array new concatenated array
Get a slice of an array
Parameters:
-
array arr: Array -
real start: Start index, inclusive -
real end: End index, exclusive
Returns: array new array containing the items from start to end
Call a function for each item in an array
Parameters:
-
array arr: Array -
function fn: Function called with(item)for each item
Create a shallow copy of a map
Parameters:
-
map m: Map
Returns: map copy
Remove all the entries from a map
Parameters:
-
map m: Map
Get the current entry capacity of a map
Parameters:
-
map m: Map
Returns: real
Get the number of live entries in a map
Parameters:
-
map m: Map
Returns: real
Check if two maps have the same size and equal entries
Parameters:
-
map a: First map -
map b: Second map
Returns: bool
Get all the keys in a map
Parameters:
-
map m: Map
Returns: array of keys
Get all the values in a map
Parameters:
-
map m: Map
Returns: array of values
Check if a map has a key
Parameters:
-
map m: Map -
any key: Key to check for
Returns: bool
Get a value from a map, or a default value if the key is not present
Parameters:
-
map m: Map -
any key: Key to look up -
any default: Value to return if the key is not present
Returns: any
Remove a key from a map
Parameters:
-
map m: Map -
any key: Key to remove
Returns: bool whether the key existed and was removed
Call a function for each entry in a map
Parameters:
-
map m: Map -
function fn: Function called with(key, value)for each entry