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, 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 and optional call stack level.
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.
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 numeric key-value pairs in the table.
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.
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
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<T1, T2>(a: T1, b: T2): 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<K, V> | 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: any): anyselect
Returns a subset of arguments or 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.
function setmetatable<T, MT>(t: T, mt: MT): Ttonumber
Converts the input string to a number in the specified base.
function tonumber(value: string | undefined | number, base?: number): number | undefinedtostring
Converts the input object to a string.
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 parameters args, handling errors with e 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 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