Skip to content

Wi Standard Library Reference

cyxigo edited this page Jul 26, 2026 · 4 revisions

Introduction

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

base

Functions

print

Print values to the standard output
Parameters:

  • any ...args: Values to print

input

Read a line from standard input
Returns: string read line, or null on end of input

load_foreign

Load foreign library
Parameters:

  • string path: Foreign library path (relative to foreign folder)

is_main

Check if current script is the main one, i.e. the script used to start program execution
Returns: bool

exit

Request the state to stop execution

error

Raise a runtime error
Parameters:

  • string message: Error message

assert

Raise a runtime error if the value is falsy
Parameters:

  • any value: Value to check
  • string message: Error message

Returns: bool

try

Safely execute an error-prone function
Parameters:

  • function fn: Function to execute
  • any ...args: Function arguments

Returns: object with fields ok, value, and error

type

Get value type
Parameters:

  • any value: Value

Returns: string value type

is_real

Check if the value is a real value
Parameters:

  • any value: Value to check

Returns: bool

is_null

Check if the value is a null value
Parameters:

  • any value: Value to check

Returns: bool

is_bool

Check if the value is a bool value
Parameters:

  • any value: Value to check

Returns: bool

is_string

Check if the value is a string
Parameters:

  • any value: Value to check

Returns: bool

is_array

Check if the value is an array
Parameters:

  • any value: Value to check

Returns: bool

is_map

Check if the value is a map
Parameters:

  • any value: Value to check

Returns: bool

is_foreign

Check if the value is a foreign function
Parameters:

  • any value: Value to check

Returns: bool

is_function

Check if the value is a function
Parameters:

  • any value: Value to check

Returns: bool

is_object

Check if the value is an object
Parameters:

  • any value: Value to check

Returns: bool

is_userdata

Check if the value is a userdata
Parameters:

  • any value: Value to check

Returns: bool

is_falsy

Check if the value is falsy
Parameters:

  • any value: Value to check

Returns: bool

to_real

Try and convert a value to a real value
Parameters:

  • any value: Value to convert

Returns: real converted value

to_bool

Try and convert a value to a bool value
Parameters:

  • any value: Value to convert

Returns: bool converted value

to_string

Try and convert a value to a string
Parameters:

  • any value: Value to convert

Returns: string converted value

has_field

Check if an object has a field
Parameters:

  • object obj: Object
  • string field: Field name

Returns: bool

fields

Get an object's fields as a map
Parameters:

  • object obj: Object

Returns: map object fields

os

Functions

clock

Get the number of CPU seconds elapsed since the program started
Returns: real

time

Get the current Unix timestamp (seconds since epoch)
Returns: real

get_env

Get the value of an environment variable
Parameters:

  • string name: Environment variable name

Returns: string value, or null if not set

args

Get the command line arguments passed to the script after the --
Returns: array of string arguments

math

Constants

E

Value: 2.7182818284590452354

PI

Value: 3.14159265358979323846

HUGE

Value: inf

Functions

abs

Get the absolute value of a number
Parameters:

  • real x: Value

Returns: real

acos

Get the arc cosine of a number, in radians
Parameters:

  • real x: Value

Returns: real

asin

Get the arc sine of a number, in radians
Parameters:

  • real x: Value

Returns: real

atan

Get the arc tangent of a number, in radians
Parameters:

  • real x: Value

Returns: real

ceil

Round a number up to the nearest integer
Parameters:

  • real x: Value

Returns: real

cos

Get the cosine of an angle given in radians
Parameters:

  • real x: Angle, in radians

Returns: real

deg

Convert an angle from radians to degrees
Parameters:

  • real x: Angle, in radians

Returns: real angle, in degrees

exp

Get e raised to the given power
Parameters:

  • real x: Exponent

Returns: real

floor

Round a number down to the nearest integer
Parameters:

  • real x: Value

Returns: real

mod

Get the floating-point remainder of a / b
Parameters:

  • real a: Dividend
  • real b: Divisor

Returns: real

log

Get the logarithm of a value with the given base
Parameters:

  • real value: Value
  • real base: Logarithm base

Returns: real

log10

Get the base-10 logarithm of a value
Parameters:

  • real x: Value

Returns: real

ln

Get the natural logarithm (base e) of a value
Parameters:

  • real x: Value

Returns: real

max

Get the largest of the given values
Parameters:

  • real ...values: Values to compare (at least one)

Returns: real

min

Get the smallest of the given values
Parameters:

  • real ...values: Values to compare (at least one)

Returns: real

pow

Raise a number to the given power
Parameters:

  • real base: Base
  • real exp: Exponent

Returns: real

rad

Convert an angle from degrees to radians
Parameters:

  • real x: Angle, in degrees

Returns: real angle, in radians

random

Get a pseudo-random real number in the range [0, 1)
Returns: real

round

Round a number to the nearest integer
Parameters:

  • real x: Value

Returns: real

sin

Get the sine of an angle given in radians
Parameters:

  • real x: Angle, in radians

Returns: real

sqrt

Get the square root of a number
Parameters:

  • real x: Value

Returns: real

tan

Get the tangent of an angle given in radians
Parameters:

  • real x: Angle, in radians

Returns: real

utf8

Functions

len

Get the number of the UTF-8 codepoints in a string
Parameters:

  • string str: String

Returns: real

at

Get the UTF-8 codepoint at the given index
Parameters:

  • string str: String
  • real index: Codepoint index

Returns: string single codepoint

string

Functions

sub

Get a substring
Parameters:

  • string str: String
  • real start: Start index, inclusive
  • real end: End index, exclusive

Returns: string substring from start to end

upper

Convert a string to uppercase
Parameters:

  • string str: String

Returns: string

lower

Convert a string to lowercase
Parameters:

  • string str: String

Returns: string

trim

Remove leading and trailing whitespace from a string
Parameters:

  • string str: String

Returns: string

has

Check if a string contains a substring
Parameters:

  • string str: String
  • string target: Substring to search for

Returns: bool

starts_with

Check if a string starts with a prefix
Parameters:

  • string str: String
  • string prefix: Prefix to check for

Returns: bool

ends_with

Check if a string ends with a suffix
Parameters:

  • string str: String
  • string suffix: Suffix to check for

Returns: bool

replace

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

Split a string by a separator
Parameters:

  • string str: String
  • string sep: Separator

Returns: array of string parts

reverse

Reverse a string
Parameters:

  • string str: String

Returns: string

array

Functions

copy

Create a shallow copy of an array
Parameters:

  • array arr: Array

Returns: array copy

clear

Remove all the items from an array
Parameters:

  • array arr: Array

capacity

Get the current item capacity of an array
Parameters:

  • array arr: Array

Returns: real

count

Get the number of the items in an array
Parameters:

  • array arr: Array

Returns: real

equals

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

Reverse an array
Parameters:

  • array arr: Array

Returns: array the same array, reversed

reversed

Get a new array with the items in reverse order
Parameters:

  • array arr: Array

Returns: array new reversed array

add

Add a value to the end of an array
Parameters:

  • array arr: Array
  • any value: Value to add

Returns: any the added value

has

Check if an array contains a value
Parameters:

  • array arr: Array
  • any value: Value to search for

Returns: bool

remove

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_at

Remove the item at the given index
Parameters:

  • array arr: Array
  • real index: Index to remove

Returns: any the removed value

pop

Remove the last item of an array
Parameters:

  • array arr: Array

Returns: any the removed value

concat

Concatenate multiple arrays into a new array
Parameters:

  • array ...arrays: Arrays to concatenate

Returns: array new concatenated array

slice

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

each

Call a function for each item in an array
Parameters:

  • array arr: Array
  • function fn: Function called with (item) for each item

map

Functions

copy

Create a shallow copy of a map
Parameters:

  • map m: Map

Returns: map copy

clear

Remove all the entries from a map
Parameters:

  • map m: Map

capacity

Get the current entry capacity of a map
Parameters:

  • map m: Map

Returns: real

count

Get the number of live entries in a map
Parameters:

  • map m: Map

Returns: real

equals

Check if two maps have the same size and equal entries
Parameters:

  • map a: First map
  • map b: Second map

Returns: bool

keys

Get all the keys in a map
Parameters:

  • map m: Map

Returns: array of keys

values

Get all the values in a map
Parameters:

  • map m: Map

Returns: array of values

has

Check if a map has a key
Parameters:

  • map m: Map
  • any key: Key to check for

Returns: bool

get_or_default

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

Remove a key from a map
Parameters:

  • map m: Map
  • any key: Key to remove

Returns: bool whether the key existed and was removed

each

Call a function for each entry in a map
Parameters:

  • map m: Map
  • function fn: Function called with (key, value) for each entry

Clone this wiki locally