print(x:string) | output any value to the console (with linefeed). |
string(x:string) -> string | convert any value to string |
set_print_depth(depth:int) -> int | for printing / string conversion: sets max vectors/objects recursion depth (default 10), returns old value |
set_print_length(len:int) -> int | for printing / string conversion: sets max string length (default 100000), returns old value |
set_print_quoted(quoted:bool) -> int | for printing / string conversion: if the top level value is a string, whether to convert it with escape codes and quotes (default false), returns old value |
set_print_decimals(decimals:int) -> int | for printing / string conversion: number of decimals for any floating point output (default -1, meaning all), returns old value |
set_print_indent(spaces:int) -> int | for printing / string conversion: number of spaces to indent with. default is 0: no indent / no multi-line, returns old value |
get_line(prefix:string) -> string | reads a string from the console if possible (followed by enter). Prefix will be printed before the input |
append(xs:[any], ys:[any]) -> [any] | creates a new vector by appending all elements of 2 input vectors |
append_into(dest:[any], src:[any]) -> [any] | appends all elements of the second vector into the first |
vector_capacity(xs:[any], len:int) -> [any] | ensures the vector capacity (number of elements it can contain before re-allocating) is at least "len". Does not actually add (or remove) elements. This function is just for efficiency in the case the amount of "push" operations is known. returns original vector. |
length(x:int) -> int | length of int (identity function, useful in combination with string/vector version) |
length(s:string) -> int | length of string |
length(xs:[any]) -> int | length of vector |
equal(a, b) -> int | structural equality between any two values (recurses into vectors/objects, unlike == which is only true for vectors/objects if they are the same object) |
push(xs:[any], x) -> [any] | appends one element to a vector, returns existing vector |
pop(xs:[any]) -> any | removes last element from vector and returns it |
top(xs:[any]) -> any | returns last element from vector |
insert(xs:[any], i:int, x) -> [any] | inserts a value into a vector at index i, existing elements shift upward, returns original vector |
remove(xs:[any], i:int) -> any | remove element at index i, following elements shift down. returns the element removed. |
remove_range(xs:[any], i:int, n:int) | remove n elements at index i, following elements shift down. |
remove_obj(xs:[any], obj) -> any | remove all elements equal to obj (==), returns obj. |
binary_search(xs:[int], key:int) -> int, int | does a binary search for key in a sorted vector, returns as first return value how many matches were found, and as second the index in the array where the matches start (so you can read them, overwrite them, or remove them), or if none found, where the key could be inserted such that the vector stays sorted. This overload is for int vectors and keys. |
binary_search(xs:[float], key:float) -> int, int | float version. |
binary_search(xs:[string], key:string) -> int, int | string version. |
binary_search_object(xs:[any], key) -> int, int | object version. compares by reference rather than contents. |
binary_search_first_field_string(xs:[any], key:string) -> int, int | object version where key is the first field (must be string, runtime error if it is not) |
binary_search_first_field_object(xs:[any], key) -> int, int | object version where key is the first field (must be object, runtime error if it is not) |
copy(x) -> any | makes a shallow copy of any object/vector/string. |
deepcopy(x, depth:int) -> any | makes a deep copy of any object/vector/string. DAGs become trees, and cycles will clone until it reach the given depth. depth == 1 would do the same as copy. |
slice(xs:[any], start:int, size:int) -> [any] | returns a sub-vector of size elements from index start. size can be negative to indicate the rest of the vector. |
any(xs:[any]) -> int | returns whether any elements of the vector are true values |
any(xs:vec_i) -> int | returns whether any elements of the numeric struct are true values |
all(xs:[any]) -> int | returns whether all elements of the vector are true values |
all(xs:vec_i) -> int | returns whether all elements of the numeric struct are true values |
substring(s:string, start:int, size:int) -> string | returns a substring of size characters from index start. size can be negative to indicate the rest of the string. |
find_string(s:string, substr:string, offset:int = 0) -> int | finds the index at which substr first appears, or -1 if none. optionally start at a position other than 0 |
find_string_reverse(s:string, substr:string, offset:int = 0) -> int | finds the index at which substr first appears when searching from the end, or -1 if none. optionally start at a position other than the end of the string |
replace_string(s:string, a:string, b:string, count:int = 0) -> string | returns a copy of s where all occurrences of a have been replaced with b. if a is empty, no replacements are made. if count is specified, makes at most that many replacements |
string_to_int(s:string, base:int = 0) -> int, int | converts a string to an int given the base (2..36, e.g. 16 for hex, default is 10).returns 0 if no numeric data could be parsed; second return value is true if allcharacters of the string were parsed. |
string_to_float(s:string) -> float, int | converts a string to a float. returns 0.0 if no numeric data could be parsed;second return value is true if all characters of the string were parsed. |
tokenize(s:string, delimiters:string, whitespace:string, dividing:int = 0) -> [string] | splits a string into a vector of strings, by splitting into segments upon each dividing or terminating delimiter. Segments are stripped of leading and trailing whitespace. Example: "; A ; B C;; " becomes [ "", "A", "B C", "" ] with ";" as delimiter and " " as whitespace. If dividing was true, there would be a 5th empty string element. |
unicode_to_string(us:[int]) -> string | converts a vector of ints representing unicode values to a UTF-8 string. |
string_to_unicode(s:string) -> [int], int | converts a UTF-8 string into a vector of unicode values. second return value is false if there was a decoding error, and the vector will only contain the characters up to the error |
number_to_string(number:int, base:int, minchars:int) -> string | converts the (unsigned version) of the input integer number to a string given the base (2..36, e.g. 16 for hex) and outputting a minimum of characters (padding with 0). |
lowercase(s:string) -> string | converts a UTF-8 string from any case to lower case, affecting only A-Z |
uppercase(s:string) -> string | converts a UTF-8 string from any case to upper case, affecting only a-z |
escape_string(s:string, set:string, prefix:string, postfix:string) -> string | prefixes & postfixes any occurrences or characters in set in string s |
concat_string(v:[string], sep:string) -> string | concatenates all elements of the string vector, separated with sep. |
repeat_string(s:string, n:int) -> string | returns a string consisting of n copies of the input string. |
pow(a:int, b:int) -> int | a raised to the power of b, for integers, using exponentiation by squaring |
pow(a:float, b:float) -> float | a raised to the power of b |
pow(a:vec_f, b:float) -> vec_f | vector elements raised to the power of b |
log(a:float) -> float | natural logaritm of a |
log2(a:float) -> float | base 2 logaritm of a |
sqrt(f:float) -> float | square root |
ceiling(f:float) -> int | the nearest int >= f |
ceiling(v:vec_f) -> vec_i | the nearest ints >= each component of v |
floor(f:float) -> int | the nearest int <= f |
floor(v:vec_f) -> vec_i | the nearest ints <= each component of v |
int(f:float) -> int | converts a float to an int by dropping the fraction |
int(v:vec_f) -> vec_i | converts a vector of floats to ints by dropping the fraction |
round(f:float) -> int | converts a float to the closest int |
round(v:vec_f) -> vec_i | converts a vector of floats to the closest ints |
fraction(f:float) -> float | returns the fractional part of a float: short for f - floor(f) |
fraction(v:vec_f) -> vec_f | returns the fractional part of a vector of floats |
float(i:int) -> float | converts an int to float |
float(v:vec_i) -> vec_f | converts a vector of ints to floats |
sin(angle:float) -> float | the y coordinate of the normalized vector indicated by angle (in degrees) |
sin(angle:vec_f) -> vec_f | the y coordinates of the normalized vector indicated by the angles (in degrees) |
cos(angle:float) -> float | the x coordinate of the normalized vector indicated by angle (in degrees) |
cos(angle:vec_f) -> vec_f | the x coordinates of the normalized vector indicated by the angles (in degrees) |
tan(angle:float) -> float | the tangent of an angle (in degrees) |
tan(angle:vec_f) -> vec_f | the tangents of the angles (in degrees) |
sincos(angle:float) -> float2 | the normalized vector indicated by angle (in degrees), same as xy { cos(angle), sin(angle) } |
asin(y:float) -> float | the angle (in degrees) indicated by the y coordinate projected to the unit circle |
acos(x:float) -> float | the angle (in degrees) indicated by the x coordinate projected to the unit circle |
atan(x:float) -> float | the angle (in degrees) indicated by the y coordinate of the tangent projected to the unit circle |
radians(angle:float) -> float | converts an angle in degrees to radians |
degrees(angle:float) -> float | converts an angle in radians to degrees |
atan2(vec:float2) -> float | the angle (in degrees) corresponding to a normalized 2D vector |
radians(angle:float) -> float | converts an angle in degrees to radians |
degrees(angle:float) -> float | converts an angle in radians to degrees |
normalize(vec:vec_f) -> vec_f | returns a vector of unit length |
dot(a:vec_f, b:vec_f) -> float | the length of vector a when projected onto b (or vice versa) |
magnitude(v:vec_f) -> float | the geometric length of a vector |
magnitude_squared(v:vec_f) -> float | the geometric length of a vector squared |
magnitude_squared(v:vec_i) -> int | the geometric length of a vector squared |
manhattan(v:vec_i) -> int | the manhattan distance of a vector |
cross(a:float3, b:float3) -> float3 | a perpendicular vector to the 2D plane defined by a and b (swap a and b for its inverse) |
volume(v:vec_f) -> float | the volume of the area spanned by the vector |
volume(v:vec_i) -> int | the volume of the area spanned by the vector |
rnd(max:int) -> int | a random value [0..max). |
rnd(max:vec_i) -> vec_i | a random vector within the range of an input vector. |
rnd_float() -> float | a random float [0..1) |
rnd_gaussian() -> float | a random float in a gaussian distribution with mean 0 and stddev 1 |
rnd_seed(seed:int) | explicitly set a random seed for reproducable randomness |
rndm(max:int) -> int | deprecated: old mersenne twister version of the above for backwards compat. |
rndm_seed(seed:int) | deprecated: old mersenne twister version of the above for backwards compat. |
div(a:int, b:int) -> float | forces two ints to be divided as floats |
clamp(x:int, min:int, max:int) -> int | forces an integer to be in the range between min and max (inclusive) |
clamp(x:float, min:float, max:float) -> float | forces a float to be in the range between min and max (inclusive) |
clamp(x:vec_i, min:vec_i, max:vec_i) -> vec_i | forces an integer vector to be in the range between min and max (inclusive) |
clamp(x:vec_f, min:vec_f, max:vec_f) -> vec_f | forces a float vector to be in the range between min and max (inclusive) |
in_range(x:int, range:int, bias:int = 0) -> int | checks if an integer is >= bias and < bias + range. Bias defaults to 0. |
in_range(x:float, range:float, bias:float = 0.000000) -> int | checks if a float is >= bias and < bias + range. Bias defaults to 0. |
in_range(x:int2, range:int2, bias:int2 = nil) -> int | checks if a 2d integer vector is >= bias and < bias + range. Bias defaults to 0. |
in_range(x:int3, range:int3, bias:int3 = nil) -> int | checks if a 3d integer vector is >= bias and < bias + range. Bias defaults to 0. |
in_range(x:float2, range:float2, bias:float2 = nil) -> int | checks if a 2d float vector is >= bias and < bias + range. Bias defaults to 0. |
in_range(x:float3, range:float3, bias:float3 = nil) -> int | checks if a 2d float vector is >= bias and < bias + range. Bias defaults to 0. |
abs(x:int) -> int | absolute value of an integer |
abs(x:float) -> float | absolute value of a float |
abs(x:vec_i) -> vec_i | absolute value of an int vector |
abs(x:vec_f) -> vec_f | absolute value of a float vector |
sign(x:int) -> int | sign (-1, 0, 1) of an integer |
sign(x:float) -> int | sign (-1, 0, 1) of a float |
sign(x:vec_i) -> vec_i | signs of an int vector |
sign(x:vec_f) -> vec_i | signs of a float vector |
min(x:int, y:int) -> int | smallest of 2 integers. |
min(x:float, y:float) -> float | smallest of 2 floats. |
min(x:vec_i, y:vec_i) -> vec_i | smallest components of 2 int vectors |
min(x:vec_f, y:vec_f) -> vec_f | smallest components of 2 float vectors |
min(v:vec_i) -> int | smallest component of a int vector. |
min(v:vec_f) -> float | smallest component of a float vector. |
min(v:[int]) -> int | smallest component of a int vector, or INT_MAX if length 0. |
min(v:[float]) -> float | smallest component of a float vector, or FLT_MAX if length 0. |
max(x:int, y:int) -> int | largest of 2 integers. |
max(x:float, y:float) -> float | largest of 2 floats. |
max(x:vec_i, y:vec_i) -> vec_i | largest components of 2 int vectors |
max(x:vec_f, y:vec_f) -> vec_f | largest components of 2 float vectors |
max(v:vec_i) -> int | largest component of a int vector. |
max(v:vec_f) -> float | largest component of a float vector. |
max(v:[int]) -> int | largest component of a int vector, or INT_MIN if length 0. |
max(v:[float]) -> float | largest component of a float vector, or FLT_MIN if length 0. |
lerp(x:float, y:float, f:float) -> float | linearly interpolates between x and y with factor f [0..1] |
lerp(a:vec_f, b:vec_f, f:float) -> vec_f | linearly interpolates between a and b vectors with factor f [0..1] |
spherical_lerp(a:float4, b:float4, f:float) -> float4 | spherically interpolates between a and b quaternions with factor f [0..1] |
smoothmin(x:float, y:float, k:float) -> float | k is the influence range |
smoothstep(x:float) -> float | input must be in range 0..1, https://en.wikipedia.org/wiki/Smoothstep |
smoothstep(a:float, b:float, f:float) -> float | hermite interpolation between a and b by f [0..1], https://registry.khronos.org/OpenGL-Refpages/gl4/html/smoothstep.xhtml |
smootherstep(x:float) -> float | input must be in range 0..1, https://en.wikipedia.org/wiki/Smoothstep |
cardinal_spline(z:vec_f, a:vec_f, b:vec_f, c:vec_f, f:float, tension:float) -> vec_f | computes the position between a and b with factor f [0..1], using z (before a) and c (after b) to form a cardinal spline (tension at 0.5 is a good default) |
line_intersect(line1a:float2, line1b:float2, line2a:float2, line2b:float2) -> int, float2 | computes if there is an intersection point between 2 line segments, with the point as second return value |
circles_within_range(dist:float, positions:[float2], radiuses:[float], positions2:[float2], radiuses2:[float], gridsize:int2) -> [[int]] | Given a vector of 2D positions (and same size vectors of radiuses), returns a vector of vectors of indices (to the second set of positions and radiuses) of the circles that are within dist of eachothers radius. If the second set are [], the first set is used for both (and the self element is excluded). gridsize optionally specifies the size of the grid to use for accellerated lookup of nearby points. This is essential for the algorithm to be fast, too big or too small can cause slowdown. Omit it, and a heuristic will be chosen for you, which is currently sqrt(num_circles) * 2 along each dimension, e.g. 100 elements would use a 20x20 grid. Efficiency wise this algorithm is fastest if there is not too much variance in the radiuses of the second set and/or the second set has smaller radiuses than the first. |
wave_function_collapse(tilemap:[string], size:int2) -> [string], int | returns a tilemap of given size modelled after the possible shapes in the input tilemap. Tilemap should consist of chars in the 0..127 range. Second return value the number of failed neighbor matches, this should ideally be 0, but can be non-0 for larger maps. Simply call this function repeatedly until it is 0 |
hash(x:int) -> int | hashes an int value into a positive int; may be the identity function |
hash(x) -> int | hashes any ref value into a positive int |
hash(x:function) -> int | hashes a function value into a positive int |
hash(x:float) -> int | hashes a float value into a positive int |
hash(v:vec_i) -> int | hashes a int vector into a positive int |
hash(v:vec_f) -> int | hashes a float vector into a positive int |
call_function_value(x:function) | calls a void / no args function value.. you shouldn't need to use this, it is a demonstration of how native code can call back into Lobster |
type_id(ref) -> int | int uniquely representing the type of the given reference (object/vector/string/resource). this is the same as typeof, except dynamic (accounts for subtypes of the static type). useful to compare the types of objects quickly. specializations of a generic type will result in different ids. |
type_string(ref) -> string | string representing the type of the given reference (object/vector/string/resource) |
type_element_string(v:[any]) -> string | string representing the type of the elements of a vector |
type_field_count(obj) -> int | number of fields in an object, or 0 for other reference types |
type_field_string(obj, idx:int) -> string | string representing the type of a field in an object, or empty for other reference types |
type_field_name(obj, idx:int) -> string | name of a field in an object, or empty for other reference types |
type_field_value(obj, idx:int) -> string | string representing the value of a field in an object, or empty for other reference types |
program_name() -> string | returns the name of the main program (e.g. "foo.lobster"), "" if running from lpak. |
vm_compiled_mode() -> int | returns if the VM is running in compiled mode (Lobster -> C++), or false for JIT. |
seconds_elapsed() -> float | seconds since program start as a float, unlike gl.time() it is calculated every time it is called |
date_time(utc:bool = false) -> [int] | a vector of integers representing date & time information (index with date_time.lobster). By default returns local time, pass true for UTC instead. |
date_time_string(utc:bool = false) -> string | a string representing date & time information in the format: 'Www Mmm dd hh:mm:ss yyyy'. By default returns local time, pass true for UTC instead. |
date_time_string_format(format:string, utc:bool = false) -> string | a string representing date & time information using a formatting string according to https://en.cppreference.com/w/cpp/chrono/c/strftime, for example "%Y_%m_%d_%H_%M_%S". By default returns local time, pass true for UTC instead. |
date_time_build_info() -> string | a string representing information from when this program was compiled. |
assert(condition) -> any | halts the program with an assertion failure if passed false. returns its input. runtime errors like this will contain a stack trace if --runtime-stack-trace is on. |
get_stack_trace() -> string | gets a stack trace of the current location of the program (needs --runtime-stack-trace) without actually stopping the program. |
get_memory_usage(n:int) -> string | gets a text showing the top n object types that are using the most memory. |
pass() | does nothing. useful for empty bodies of control structures. |
trace_bytecode(mode:int) | tracing shows each bytecode instruction as it is being executed, not very useful unless you are trying to isolate a compiler bug. Mode is off(0), on(1) or tail only (2) |
reference_count(val) -> int | get the reference count of any value. for compiler debugging, mostly |
set_console(on:bool) | lets you turn on/off the console window (on Windows) |
set_output_level(level:int) | 0 = debug, 1 = verbose, 2 = warn (default), 3 = error, 4 = program |
set_exit_code(code:int) | this will be returned when run as a console application |
command_line_arguments() -> [string] | |
thread_information() -> int, int | returns the number of hardware threads, and the number of cores |
is_worker_thread() -> int | whether the current thread is a worker thread |
start_worker_threads(numthreads:int) | launch worker threads |
stop_worker_threads() | only needs to be called if you want to stop the worker threads before the end of the program, or if you want to call start_worker_threads again. workers_alive will become false inside the workers, which should then exit. |
workers_alive() -> int | whether workers should continue doing work. returns false after stop_worker_threads() has been called. |
thread_write(struct) | put this struct in the thread queue |
thread_read(type:typeid(any)) -> any? | get a struct from the thread queue. pass the typeof struct. blocks if no suchstructs available. returns struct, or nil if stop_worker_threads() was called |
thread_check(type:typeid(any)) -> any? | tests if a struct is available on the thread queue. pass the typeof struct. returns struct, or nil if none available, or if stop_worker_threads() was called |
crash_test_cpp_nullptr_exception() | only for testing crash dump functionality, don't use! :) |
scan_folder(folder:string, rel:bool = false) -> [string]?, [int]? | returns two vectors representing all elements in a folder, the first vector containing all names, the second vector containing sizes in bytes (or -1 if a directory). set rel use a relative path, default is absolute. Returns nil if folder couldn't be scanned. |
read_file(file:string, textmode:int = 0) -> string? | returns the contents of a file as a string, or nil if the file can't be found. you may use either \ or / as path separators |
write_file(file:string, contents:string, textmode:int = 0, absolute_path:int = 0) -> int | creates a file with the contents of a string, returns false if writing wasn't possible |
rename_file(old_file:string, new_file:string) -> int | renames a file, returns false if it wasn't possible |
delete_file(file:string) -> int | deletes a file, returns false if it wasn't possible. Will search in all import dirs. |
exists_file(file:string) -> int | checks wether a file exists. |
launch_subprocess(commandline:[string], stdin:string = nil) -> int, string | launches a sub process, with optionally a stdin for the process, and returns its return code (or -1 if it couldn't launch at all), and any output |
vector_to_buffer(vec:[any], width:int = 4) -> string | converts a vector of ints/floats (or structs of them) to a buffer, where each scalar is written with "width" bytes (1/2/4/8, default 4). Returns nil if the type couldn't be converted. Uses native endianness. |
ensure_size(string:string, size:int, char:int, extra:int = 0) -> string | ensures a string is at least size characters. if it is, just returns the existing string, otherwise returns a new string of that size (with optionally extra bytes added), with any new characters set to char. You can specify a negative size to mean relative to the end, i.e. new characters will be added at the start. |
write_int64_le(string:string, i:int, val:int) -> string, int | writes a value as little endian to a string at location i. Uses ensure_size to make the string twice as long (with extra 0 bytes) if no space. Returns new string if resized, and the index of the location right after where the value was written. The _back version writes relative to the end (and writes before the index) |
write_int32_le(string:string, i:int, val:int) -> string, int | (see write_int64_le) |
write_int16_le(string:string, i:int, val:int) -> string, int | (see write_int64_le) |
write_int8_le(string:string, i:int, val:int) -> string, int | (see write_int64_le) |
write_float64_le(string:string, i:int, val:float) -> string, int | (see write_int64_le) |
write_float32_le(string:string, i:int, val:float) -> string, int | (see write_int64_le) |
write_int64_le_back(string:string, i:int, val:int) -> string, int | (see write_int64_le) |
write_int32_le_back(string:string, i:int, val:int) -> string, int | (see write_int64_le) |
write_int16_le_back(string:string, i:int, val:int) -> string, int | (see write_int64_le) |
write_int8_le_back(string:string, i:int, val:int) -> string, int | (see write_int64_le) |
write_float64_le_back(string:string, i:int, val:float) -> string, int | (see write_int64_le) |
write_float32_le_back(string:string, i:int, val:float) -> string, int | (see write_int64_le) |
write_substring(string:string, i:int, substr:string, nullterm:int) -> string, int | writes a substring into another string at i (see also write_int64_le) |
write_substring_back(string:string, i:int, substr:string, nullterm:int) -> string, int | |
compare_substring(string_a:string, i_a:int, string_b:string, i_b:int, len:int) -> int | returns if the two substrings are equal (0), or a < b (-1) or a > b (1). |
read_int64_le(string:string, i:int) -> int, int | reads a value as little endian from a string at location i. The value must be within bounds of the string. Returns the value, and the index of the location right after where the value was read. The _back version reads relative to the end (and reads before the index) |
read_int32_le(string:string, i:int) -> int, int | (see read_int64_le) |
read_int16_le(string:string, i:int) -> int, int | (see read_int64_le) |
read_int8_le(string:string, i:int) -> int, int | (see read_int64_le) |
read_uint64_le(string:string, i:int) -> int, int | reads a value as little endian from a string at location i. The value must be within bounds of the string. Returns the value, and the index of the location right after where the value was read. The _back version reads relative to the end (and reads before the index) |
read_uint32_le(string:string, i:int) -> int, int | (see read_int64_le) |
read_uint16_le(string:string, i:int) -> int, int | (see read_int64_le) |
read_uint8_le(string:string, i:int) -> int, int | (see read_int64_le) |
read_float64_le(string:string, i:int) -> float, int | (see read_int64_le) |
read_float32_le(string:string, i:int) -> float, int | (see read_int64_le) |
read_int64_le_back(string:string, i:int) -> int, int | (see read_int64_le) |
read_int32_le_back(string:string, i:int) -> int, int | (see read_int64_le) |
read_int16_le_back(string:string, i:int) -> int, int | (see read_int64_le) |
read_int8_le_back(string:string, i:int) -> int, int | (see read_int64_le) |
read_uint64_le_back(string:string, i:int) -> int, int | (see read_int64_le) |
read_uint32_le_back(string:string, i:int) -> int, int | (see read_int64_le) |
read_uint16_le_back(string:string, i:int) -> int, int | (see read_int64_le) |
read_uint8_le_back(string:string, i:int) -> int, int | (see read_int64_le) |
read_float64_le_back(string:string, i:int) -> float, int | (see read_int64_le) |
read_float32_le_back(string:string, i:int) -> float, int | (see read_int64_le) |