Global Functions
Lua and SLua global functions
Lua standard globals
Standard Lua functions available in the SLua runtime:
assert
Checks if the value is truthy; if not, raises an error with the optional message. Returns the value upon success.
function assert<T>(value?: T, errorMessage?: string): Tcollectgarbage
Alias for gcinfo
function collectgarbage(option: "count"): numbercollectgarbage
Run the garbage collector
function collectgarbage(option?: "collect"): voiderror
Raises an error with the specified object. The optional level determines which call stack level is blamed for the error.
function error<T>(message: T, level?: number): nevergcinfo
Returns the total heap size in kilobytes.
function gcinfo(): numbergetfenv
Get the scoped environment for the given function.
function getfenv(target: ((this: void, ...args: any[]) => any[]) | number): Record<string, any>getmetatable
Returns the metatable for the specified object. If the metatable has a '__metatable' field, returns its value instead.
function getmetatable<T>(obj: T): Record<string, any> | undefinedgraphheap
Writes the contents of heap to the given file in JSON format. Intended to be used with tools/graphanalyze.py
function graphheap(path: string): voidgraphuserheap
Writes the contents of user heap to the given file in JSON format. Intended to be used with tools/graphanalyze.py
function graphuserheap(path: string): voidipairs
Returns an iterator for sequential integer key-value pairs in the table. Iteration starts at 1 and halts at the first nil value.
function ipairs<V>(tab: V[]): LuaMultiReturn<
[(this: void, arg0: V[], arg1: number) => LuaMultiReturn<[number | undefined, V]>, V[], number]
>loadstring
Compile Luau code into a function.
function loadstring(src: string, chunkname?: string): anynewproxy
Creates a new untyped userdata object with an optional metatable.
function newproxy(mt?: boolean): anynext
Returns the next key-value pair in the table traversal order. If the index is nil or omitted, returns the first pair.
function next<K, V>(t: Record<K, V>, i?: K): LuaMultiReturn<[K | undefined, V]>pairs
Returns an iterator for all key-value pairs in the table.
function pairs<K, V>(t: Record<K, V>): LuaMultiReturn<
[
(this: void, arg0: Record<K, V>, arg1: K | undefined) => LuaMultiReturn<[K | undefined, V]>,
Record<K, V>,
K,
]
>pcall
Executes function f in protected mode, calling it with the provided arguments. Returns a boolean indicating success. If true, it also returns the function's results. If false, it returns the error message.
function pcall(f: (...args: any[]) => any, args: any[]): anyprint
Sends all arguments as text privately to the object owner, separated by 4 spaces. The owner must be currently in the same region for the message to be received.
function print(args: any[]): voidrawequal
Returns true if a and b have the same type and value or reference, bypassing the __eq metamethod..
function rawequal<T1, T2>(a: T1, b: T2): booleanrawget
Performs a table lookup, bypassing the __index metamethod..
function rawget<K, V>(t: Record<K, V>, k: K): V | undefinedrawlen
Returns the length of a table or string, bypassing the __len metamethod..
function rawlen<K, V>(t: Record<K, V> | string): numberrawset
Assigns a value to a table field, bypassing the __newindex metamethod..
function rawset<K, V>(t: Record<K, V>, k: K, v: V): Record<K, V>require
Execute the named external module.
function require(target: any): anyselect
Returns a subset of arguments starting from the specified index. Supports negative indexing. If index is '#', returns the number of arguments.
function select(i: string | number, args: any[]): any[]setfenv
Set the scoped environment for the given function.
function setfenv(target: number | ((...args: any[]) => any), env: Record<string, any>): anysetmetatable
Changes the metatable for the given table. Raises an error if the table already has a protected metatable (it has a '__metatable' field).
function setmetatable<T, MT>(t: T, mt: MT): Ttonumber
Converts the input string to a number in the specified base. Returns nil if invalid.
function tonumber(value: string | undefined | number, base?: number): number | undefinedtostring
Converts the input object to a string. Calls the metatable's '__tostring' metamethod if present.
function tostring<T>(value: T): stringtype
Returns the type of the object as a string.
function type<T>(obj: T): stringunpack
Returns values from an array in the specified index range.
function unpack<V>(tab: V[], i?: number, j?: number): V[]xpcall
Calls function f with the provided arguments, handling errors with err if they occur.
function xpcall<E>(f: (...args: any[]) => any, err: (...args: any[]) => any, args: any[]): anySLua-specific globals
toquaternion
Converts a string to a quaternion. Returns nil if invalid.
function toquaternion(value: string | undefined | Quaternion): Quaternion | undefinedtorotation
Converts a string to a rotation (quaternion). Returns nil if invalid.
function torotation(value: string | undefined | Quaternion): Quaternion | undefinedtouuid
Creates a new uuid from a string, buffer, or existing uuid. Returns nil if the string is not a valid UUID, or the buffer is shorter than 16 bytes.
function touuid(val: string | undefined | buffer | UUID): UUID | undefinedtovector
Converts a string to a vector. Returns nil if invalid.
function tovector(val: string | undefined | Vector): Vector | undefinedPlugin globals
These globals come from the transpiler plugin, not the SLua runtime.
$castRay
function $castRay<const Opts extends CastRayParamOptions>(start: Vector, end: Vector, options: Opts): CastRayResult<Opts>$createCharacter
function $createCharacter(): CharacterParamBuilder$httpRequest
function $httpRequest(url: string, options: HttpParamOptions): UUID$linkParticleSystem
function $linkParticleSystem(linkNumber: number): ParticleSystemParamBuilder$particleSystem
function $particleSystem(): ParticleSystemParamBuilder$rezObjectWithParams
function $rezObjectWithParams(inventoryItem: string): RezParamBuilder$setCameraParams
function $setCameraParams(): CameraParamBuilder$setGltfOverrides
function $setGltfOverrides(link: number, face: number): GltfOverrideParamBuilder$setPrimParams
function $setPrimParams(linkNumber: number): PrimParamBuilder$updateCharacter
function $updateCharacter(): CharacterParamBuilder