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.
function assert<T>(value?: T, message?: string): Tcollectgarbage
Run the garbage collector
function collectgarbage(option?: "collect"): voiderror
Raises an error with the specified object and optional call stack level.
function error(obj: any, 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.
function getmetatable(obj: any): Record<any, 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 numeric key-value pairs in the table.
function ipairs<V>(t: 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.
function next<K, V>(t: Record<K, V>, i?: K): LuaMultiReturn<[K, V]> | undefinedpairs
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) => LuaMultiReturn<[K | undefined, V]>, Record<K, V>, K]
>pcall
Calls function f with parameters args, returning success and function results or an error.
function pcall(f: (...args: any[]) => any, args: any[][]): anyprint
Prints all arguments to standard output using Tab as a separator.
function print(args: any[]): voidrawequal
Returns true if a and b have the same type and value.
function rawequal(a: any, b: any): booleanrawget
Performs a table lookup bypassing metatables.
function rawget<K, V>(t: Record<K, V>, k: K): V | undefinedrawlen
Returns the length of a table or string bypassing metatables.
function rawlen<K, V>(t: Record<any, any> | string): numberrawset
Assigns a value to a table field bypassing metatables.
function rawset<K, V>(t: Record<K, V>, k: K, v: V): Record<K, V>require
Execute the named external module.
function require(target: string): anyselect
Returns a subset of arguments or the number of arguments.
function select(i: string | number, args: any[]): anysetfenv
Set the scoped environment for the given function.
function setfenv(target: ((this: void, ...args: any[]) => any[]) | number, env: Record<string, any>): voidsetmetatable
Changes the metatable for the given table.
function setmetatable(t: Record<any, any>, mt?: Record<any, any>): voidtonumber
Converts the input string to a number in the specified base.
function tonumber(s: string, base?: number): number | undefinedtostring
Converts the input object to a string.
function tostring(obj: any): stringtype
Returns the type of the object as a string.
function type(obj: any): stringunpack
Returns values from an array in the specified index range.
function unpack<V>(a: V[], f?: number, t?: number): V[]xpcall
Calls function f with parameters args, handling errors with e if they occur.
function xpcall<E>(f: (...args: any[]) => any, e: (...args: any[]) => any, args: any[][]): anySLua-specific Globals
toquaternion
Converts a string to a quaternion, returns nil if invalid
function toquaternion(val: string | undefined | Quaternion): Quaternion | undefinedtorotation
Converts a string to a rotation (quaternion), returns nil if invalid
function torotation(val: 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 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 are provided by the transpiler plugin and are not part of 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