@gwigz/slua

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): T

collectgarbage

Run the garbage collector

function collectgarbage(option?: "collect"): void

error

Raises an error with the specified object and optional call stack level.

function error(obj: any, level?: number): never

gcinfo

Returns the total heap size in kilobytes.

function gcinfo(): number

getfenv

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> | undefined

graphheap

Writes the contents of heap to the given file in JSON format. Intended to be used with tools/graphanalyze.py

function graphheap(path: string): void

graphuserheap

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): void

ipairs

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): any

newproxy

Creates a new untyped userdata object with an optional metatable.

function newproxy(mt?: boolean): any

next

Returns the next key-value pair in the table traversal order.

function next<K, V>(t: Record<K, V>, i?: K): LuaMultiReturn<[K, V]> | undefined

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) => 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[][]): any

print

Prints all arguments to standard output using Tab as a separator.

function print(args: any[]): void

rawequal

Returns true if a and b have the same type and value.

function rawequal(a: any, b: any): boolean

rawget

Performs a table lookup bypassing metatables.

function rawget<K, V>(t: Record<K, V>, k: K): V | undefined

rawlen

Returns the length of a table or string bypassing metatables.

function rawlen<K, V>(t: Record<any, any> | string): number

rawset

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): any

select

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: ((this: void, ...args: any[]) => any[]) | number, env: Record<string, any>): void

setmetatable

Changes the metatable for the given table.

function setmetatable(t: Record<any, any>, mt?: Record<any, any>): void

tonumber

Converts the input string to a number in the specified base.

function tonumber(s: string, base?: number): number | undefined

tostring

Converts the input object to a string.

function tostring(obj: any): string

type

Returns the type of the object as a string.

function type(obj: any): string

unpack

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[][]): any

SLua-specific Globals

toquaternion

Converts a string to a quaternion, returns nil if invalid

function toquaternion(val: string | undefined | Quaternion): Quaternion | undefined

torotation

Converts a string to a rotation (quaternion), returns nil if invalid

function torotation(val: string | undefined | Quaternion): Quaternion | undefined

touuid

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 | undefined

tovector

Converts a string to a vector, returns nil if invalid

function tovector(val: string | undefined | Vector): Vector | undefined

Plugin 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

On this page