Globals
Embedders: to define globals within your environment, see userdata (extern types)
All language-provided globals that should be in scope in every program (unless the embedder removes or replaces them)
Summary
Output
function print(...: unknown)printInherited from Lua 5.1's standard library.
Lua- Writes its arguments to the output separated by tabs
Error handling
function assert<T>(value: T, message: string?): TassertInherited from Lua 5.1's standard library.
Lua- Raises an error when a value is falsy
function error<T>(message: T, level: number?): nevererrorInherited from Lua 5.1's standard library.
Lua- Raises an error with any value as the error object
function pcall<A..., R...>(f: (A...) -> R..., ...: A...): (boolean, R...)pcallInherited from Lua 5.1's standard library.
LuaChanged by Luau 0.501 or earlier: Can yield inside the protected call.
Luau- Calls a function and catches any error it raises
function xpcall<E, A..., R1..., R2...>( f: (A...) -> R1..., handler: (E) -> R2..., ...: A... ): (boolean, R1...)xpcallInherited from Lua 5.1's standard library.
LuaChanged by Luau 0.501 or earlier: Passes extra arguments on to the function, as Lua 5.2 does.
Changed by Luau 0.501 or earlier: Can yield inside the protected call.
Luau- Calls a function and passes any error it raises to a handler
Types and conversions
function type(value: unknown): stringtypeInherited from Lua 5.1's standard library.
LuaChanged by Luau 0.501 or earlier: Returns "vector" for a vector.
Changed by Luau 0.600: Returns "buffer" for a buffer.
Changed by Luau 0.715: Returns "integer" for an integer.
Changed by Luau 0.722: Returns "class" for a class and "object" for an object.
LuauChanged by Luwu: Returns "trait" for a trait.
Changed by Luwu: Returns "symbol" for none.
Luwu- Returns the name of a value's basic type
function typeof(value: unknown): stringtypeofAdded by Luau 0.501 or earlier.
Changed by Luau 0.600: Returns "buffer" for a buffer.
Changed by Luau 0.715: Returns "integer" for an integer.
Changed by Luau 0.722: Returns "class" for a class and "object" for an object.
LuauChanged by Luwu: Returns "trait" for a trait.
Changed by Luwu: Returns "none" for none, where type returns "symbol".
Luwu- Returns a value's type name, using the host's names for its types
function tonumber(value: unknown, base: number?): number?tonumberInherited from Lua 5.1's standard library.
Lua- Converts a value to a number or returns nil
function tostring(value: unknown): stringtostringInherited from Lua 5.1's standard library.
Lua- Converts any value to a string
Iterators
function next<K, V>(t: { [K]: V }, key: K?): (K?, V)nextInherited from Lua 5.1's standard library.
Lua- Returns the table entry that comes after a key
function pairs<K, V>(t: { [K]: V }): (({ [K]: V }, K?) -> (K?, V), { [K]: V }, nil)pairsInherited from Lua 5.1's standard library.
LuaDeprecated by Luwu (October 2026).
Loop over the table instead:
deprecatedfor key, value in t do.- Returns what a for loop needs to visit every entry of a table
function ipairs<V>(t: { V }): (({ V }, number) -> (number?, V), { V }, number)ipairsInherited from Lua 5.1's standard library.
LuaDeprecated by Luwu (October 2026).
Loop over the array instead:
deprecatedfor index, item in t do. That loop doesn't stop at the firstnil.- Returns what a for loop needs to visit an array in order
Varargs
function select<A...>(index: number | "#", ...: A...): ...unknownselectInherited from Lua 5.1's standard library.
Lua- Returns the argument count or the arguments from an index on
function unpack<V>(t: { V }, first: number?, last: number?): ...VunpackInherited from Lua 5.1's standard library.
Lua- Returns the items of an array between two indices
Metatables
function getmetatable<T>(value: T): getmetatable<T>getmetatableInherited from Lua 5.1's standard library.
Lua- Returns the metatable of a value
function setmetatable<T, MT>(t: T, metatable: MT): setmetatable<T, MT>setmetatableInherited from Lua 5.1's standard library.
Lua- Sets the metatable of a table
function rawget<K, V>(t: { [K]: V }, key: K): V?rawgetInherited from Lua 5.1's standard library.
Lua- Reads a table field without calling __index
function rawset<K, V>(t: { [K]: V }, key: K, value: V): { [K]: V }rawsetInherited from Lua 5.1's standard library.
Lua- Sets a table field without calling __newindex
function rawequal(a: unknown, b: unknown): booleanrawequalInherited from Lua 5.1's standard library.
Lua- Checks whether two values are equal without calling __eq
function rawlen<K, V>(value: { [K]: V } | string): numberrawlenBackported from Lua 5.2 by Luau 0.534.
Luau- Returns the length of a table or string without calling __len
function newproxy(with_metatable: boolean?): userdatanewproxyInherited from Lua 5.1's standard library.
LuaDeprecated by Luwu (October 2026).
Use a class for an object with methods.
deprecated- Creates an empty userdata, optionally with a metatable
Modules
function require(path: string): unknownrequireInherited from Lua 5.1's standard library.
LuaChanged by Luau 0.669: The Require library gives hosts a standard require-by-string.
Luau- Runs a module and returns the value it returns
Environments
_G: { [string]: unknown }_GInherited from Lua 5.1's standard library.
Lua- The global table
function getfenv(target: (number | (...unknown) -> ...unknown)?): { [string]: unknown }getfenvInherited from Lua 5.1's standard library.
LuaChanged by Luau 0.501 or earlier: Turns off import optimizations for the environment.
Changed by Luau 0.599: The DeprecatedApi lint warns about calls with a stack level.
LuauDeprecated by Luau.
To find out which function is calling yours, use
deprecateddebug.info.- Returns the environment table of a function
function setfenv<T..., R...>( target: number | (T...) -> R..., env: { [string]: unknown } ): ((T...) -> R...)?setfenvInherited from Lua 5.1's standard library.
LuaChanged by Luau 0.501 or earlier: Turns off import optimizations for the environment.
Changed by Luau 0.599: The DeprecatedApi lint warns about calls with a stack level.
LuauDeprecated by Luau.
Pass a function the values it needs as arguments or through a module instead.
deprecated- Sets the environment table of a function
Debugging
function gcinfo(): numbergcinfoInherited from Lua 5.1's standard library.
Lua- Returns the total heap size in kilobytes
_VERSION: string_VERSIONInherited from Lua 5.1's standard library.
Lua- A string naming the runtime
Primitives
none: nonenoneAdded by Luwu.
LuwuAvailable in luwu/integration and gated by an FFlag. We anticipate this feature to be released and enabled by default in 0.1.0.
Needs the
flaggedLuwuNonePrimitiveFFlag.- The value that means intentionally empty
Output
printInherited from Lua 5.1's standard library.
Lua
function print(...: unknown)Writes each argument to the environment's output or debug console as a string separated by tabs.
Environment-specific overrides
Embedders often override this function to add pretty printing, output to a logfile, or remove it altogether in environments without a console.
In Luwu, we expect embedders to (eventually) call __tostring on each argument, but embedders often call an embedder-defined display implementation on each argument before falling back to it. In the near future we're interested in introducing language-level __repr, __display, and __debug functions to granularly specify the semantic meaning of tostring representations across multiple environments.
Error handling
assertInherited from Lua 5.1's standard library.
Lua
function assert<T>(value: T, message: string?): TRaises an error when value is falsy (false, nil or none). The error message is message when it's given and "assertion failed!" otherwise. When value is truthy, assert returns every argument it was passed.
The type checker narrows the result. Passing a number? gives back a number:
const gold: number? = 120
const amount = assert(gold, "gold should be set")
print(amount + 5)125
errorInherited from Lua 5.1's standard library.
Lua
function error<T>(message: T, level: number?): neverRaises an error with message as the error object. The object doesn't have to be a string: pcall hands back whatever value was raised.
When message is a string, error puts the location of the call at level in front of it. Level 1 (the default) is the function that called error, level 2 is the function that called that one, and level 0 leaves the message as it is. Level 2 blames the caller when it passed a bad argument:
const function withdraw(balance: number, amount: number): number
if amount > balance then
error("not enough gold", 2)
end
return balance - amount
endpcallInherited from Lua 5.1's standard library.
LuaChanged by Luau 0.501 or earlier: Can yield inside the protected call.
Luau
function pcall<A..., R...>(f: (A...) -> R..., ...: A...): (boolean, R...)Calls f with the remaining arguments and catches any error it raises. On success it returns true followed by everything f returned. On failure it returns false and the error object. f can yield and the whole coroutine yields with it.
const ok, doubled = pcall(function(amount: number): number
return amount * 2
end, 21)
print(`{ok} {doubled}`)
const failed = pcall(error, "out of gold")
print(failed)true 42 false
xpcallInherited from Lua 5.1's standard library.
LuaChanged by Luau 0.501 or earlier: Passes extra arguments on to the function, as Lua 5.2 does.
Changed by Luau 0.501 or earlier: Can yield inside the protected call.
Luau
function xpcall<E, A..., R1..., R2...>(
f: (A...) -> R1...,
handler: (E) -> R2...,
...: A...
): (boolean, R1...)Works like pcall except that an error goes through handler first. xpcall then returns false and the handler's first result. The handler runs before the stack unwinds and debug.traceback can see where the error happened from inside it.
f can yield. The handler can't: when it yields or raises an error, xpcall returns false and "error in error handling".
const ok, result = xpcall(load_save, function(err: unknown): string
return debug.traceback(tostring(err), 2)
end, "slot1")Types and conversions
typeInherited from Lua 5.1's standard library.
LuaChanged by Luau 0.501 or earlier: Returns "vector" for a vector.
Changed by Luau 0.600: Returns "buffer" for a buffer.
Changed by Luau 0.715: Returns "integer" for an integer.
Changed by Luau 0.722: Returns "class" for a class and "object" for an object.
LuauChanged by Luwu: Returns "trait" for a trait.
Changed by Luwu: Returns "symbol" for none.
Luwu
function type(value: unknown): stringReturns the name of the value's primitive type, like "number" or "table". Primitives lists every one.
type never looks at metatables and calls every userdata "userdata". typeof gives the host's name for it instead.
print(type(42))
print(type("Ada"))
print(type(print))
print(type(buffer.create(8)))number string function buffer
typeofAdded by Luau 0.501 or earlier.
Changed by Luau 0.600: Returns "buffer" for a buffer.
Changed by Luau 0.715: Returns "integer" for an integer.
Changed by Luau 0.722: Returns "class" for a class and "object" for an object.
LuauChanged by Luwu: Returns "trait" for a trait.
Changed by Luwu: Returns "none" for none, where type returns "symbol".
Luwu
function typeof(value: unknown): stringReturns the same name as type except for values whose type the host has named. A host-defined userdata whose metatable has a __type string gives that string. Userdata from newproxy always gives "userdata" and scripts can't make a value pass for a host type. typeof(none) is "none".
print(typeof(42))
print(typeof(none))number none
tonumberInherited from Lua 5.1's standard library.
Lua
function tonumber(value: unknown, base: number?): number?Converts value to a number and returns nil when it can't. Numbers come back unchanged. In base 10 (the default), a string can be written any way a number literal can be written. That covers hexadecimal like "0x1F" and exponents like "1e3". Spaces around the number are allowed. Any other base from 2 to 36 reads the string's digits in that base, using letters for digits past 9.
print(tonumber("42"))
print(tonumber("ff", 16))
print(tonumber("0x1F"))
print(tonumber("12 gold"))42 255 31 nil
tostringInherited from Lua 5.1's standard library.
Lua
function tostring(value: unknown): stringConverts any value to a string. When the value's metatable has a __tostring metamethod, tostring calls it and returns the string it gives back. A __tostring that returns anything else raises an error. Tables, functions and other objects without one convert to their type and an address, like "table: 0x0000a1b2c3d4e5f6".
const purse = setmetatable({ amount = 120 }, {
function __tostring(self: { amount: number }): string
return `{self.amount} gold`
end,
})
print(tostring(purse))
print(tostring(none))120 gold none
Iterators
nextInherited from Lua 5.1's standard library.
Lua
function next<K, V>(t: { [K]: V }, key: K?): (K?, V)Returns the key and value that come after key in the table's traversal order, or nil after the last one. With key left out or nil, it returns the first entry. The order isn't defined. next(t) == nil checks whether a table is empty:
const empty = {}
const gold = { Ada = 120 }
print(next(empty) == nil)
print(next(gold) == nil)true false
pairsInherited from Lua 5.1's standard library.
LuaDeprecated by Luwu (October 2026).
Loop over the table instead: for key, value in t do.
deprecated
for key, value in t do.function pairs<K, V>(t: { [K]: V }): (({ [K]: V }, K?) -> (K?, V), { [K]: V }, nil)Returns the three values a for loop needs to visit every entry of a table. The order isn't defined. for key, value in t do does the same without the call. Unlike pairs, it runs the table's __iter metamethod.
ipairsInherited from Lua 5.1's standard library.
LuaDeprecated by Luwu (October 2026).
Loop over the array instead: for index, item in t do. That loop doesn't stop at the first nil.
deprecated
for index, item in t do. That loop doesn't stop at the first nil.function ipairs<V>(t: { V }): (({ V }, number) -> (number?, V), { V }, number)Returns the three values a for loop needs to visit an array in order. The loop starts at index 1, counts up by one and stops at the first nil. Items after a hole are skipped. A none in the array doesn't stop the loop.
const queue = { "Ada", "Grace", nil, "Alan" }
for index, name in ipairs(queue) do
print(`{index}: {name}`)
end1: Ada 2: Grace
Varargs
selectInherited from Lua 5.1's standard library.
Lua
function select<A...>(index: number | "#", ...: A...): ...unknownWith "#" as the first argument, select returns the number of arguments after it including any nil ones. With a number, it returns the arguments from that index on. A negative index counts from the end: -1 is the last argument.
const function count(...: unknown): number
return select("#", ...)
end
print(count(1, nil, 3))
const last = select(-1, "Ada", "Grace", "Alan")
print(last)3 Alan
unpackInherited from Lua 5.1's standard library.
Lua
function unpack<V>(t: { V }, first: number?, last: number?): ...VReturns the items of t from index first (1 by default) to last (#t by default). It's the same function as table.unpack.
const second, third = unpack({ "Ada", "Grace", "Alan" }, 2)
print(`{second} and {third}`)Grace and Alan
Metatables
getmetatableInherited from Lua 5.1's standard library.
Lua
function getmetatable<T>(value: T): getmetatable<T>Returns the metatable of value or nil when it has none. Values other than tables and userdata share one metatable per type: every string has the metatable whose __index is the string library. When the metatable has a __metatable field, getmetatable returns that field instead and it doesn't have to be a table.
setmetatableInherited from Lua 5.1's standard library.
Lua
function setmetatable<T, MT>(t: T, metatable: MT): setmetatable<T, MT>Sets the metatable of t and returns t. Passing nil removes the metatable. Only tables work here, unlike getmetatable. When the current metatable has a __metatable field it's protected and setmetatable raises an error.
const defaults = { speed = 16 }
const player = setmetatable({ name = "Ada" }, { __index = defaults })
print(player.speed)
print(rawget(player, "speed"))16 nil
rawgetInherited from Lua 5.1's standard library.
Lua
function rawget<K, V>(t: { [K]: V }, key: K): V?Reads t[key] without calling an __index metamethod. It returns nil when the table itself has no value under key.
rawsetInherited from Lua 5.1's standard library.
Lua
function rawset<K, V>(t: { [K]: V }, key: K, value: V): { [K]: V }Sets t[key] to value without calling a __newindex metamethod and returns t.
rawequalInherited from Lua 5.1's standard library.
Lua
function rawequal(a: unknown, b: unknown): booleanReturns whether a and b are the same value without calling an __eq metamethod. Tables, functions and other objects are equal only when they're the same object.
rawlenBackported from Lua 5.2 by Luau 0.534.
Luau
function rawlen<K, V>(value: { [K]: V } | string): numberReturns the length of a table or string without calling a __len metamethod. For a string it's the same as #s.
newproxyInherited from Lua 5.1's standard library.
LuaDeprecated by Luwu (October 2026).
Use a class for an object with methods.
deprecated
function newproxy(with_metatable: boolean?): userdataCreates an empty userdata. When with_metatable is true, it gets an empty metatable that getmetatable returns and scripts can fill in. typeof always gives "userdata" for these values, even when the metatable has a __type field. A script can't use them to pass for a host's type.
Modules
requireInherited from Lua 5.1's standard library.
LuaChanged by Luau 0.669: The Require library gives hosts a standard require-by-string.
Luau
function require(path: string): unknownRuns a module and returns the value it returns. A module runs once and later calls with the same module get the same value. The host provides require and decides how paths resolve. Hosts that use Luwu's Require library follow the same rules:
- A path starting with
./or../is relative to the module that callsrequire. - A path starting with
@starts with an alias, like@std. Aliases come from the project's.luaurcor from the host.
The type checker follows a require of a literal path and gives the result the module's type.
const inventory = require("./inventory")
const colors = require("@std/io/colors")Environments
_GInherited from Lua 5.1's standard library.
Lua
_G: { [string]: unknown }The global table. Reading _G.name is the same as reading the global name. In a sandboxed host the global table is read-only.
getfenvInherited from Lua 5.1's standard library.
LuaChanged by Luau 0.501 or earlier: Turns off import optimizations for the environment.
Changed by Luau 0.599: The DeprecatedApi lint warns about calls with a stack level.
LuauDeprecated by Luau.
To find out which function is calling yours, use debug.info.
deprecated
debug.info.function getfenv(target: (number | (...unknown) -> ...unknown)?): { [string]: unknown }Returns the environment table of a function. target is either the function or a level on the call stack, where 1 (the default) is the function calling getfenv. For a function written in C, getfenv returns the thread's global table.
getfenv and setfenv mark the environment as unsafe. Code using that environment loses the optimizations that rely on globals never changing, such as fast calls to builtin functions.
setfenvInherited from Lua 5.1's standard library.
LuaChanged by Luau 0.501 or earlier: Turns off import optimizations for the environment.
Changed by Luau 0.599: The DeprecatedApi lint warns about calls with a stack level.
LuauDeprecated by Luau.
Pass a function the values it needs as arguments or through a module instead.
deprecated
function setfenv<T..., R...>(
target: number | (T...) -> R...,
env: { [string]: unknown }
): ((T...) -> R...)?Sets the environment table of a function to env and returns the function. target is the function or a level on the call stack, where 1 is the function calling setfenv. Level 0 changes the running thread's environment and returns nothing. Functions written in C can't have their environment changed. Like getfenv, it turns off the optimizations that rely on globals never changing.
Debugging
gcinfoInherited from Lua 5.1's standard library.
Lua
function gcinfo(): numberReturns the total heap size in kilobytes. The heap includes bytecode, global tables and every object scripts allocated. Luwu's garbage collector is incremental and the heap can hold unreachable objects it hasn't freed yet. The number changes as the collector runs.
_VERSIONInherited from Lua 5.1's standard library.
Lua
_VERSION: stringA string naming the runtime. The VM sets it to "Luau" and hosts often replace it: in seal it reads like "seal 0.9.0+0.730".
Primitives
noneAdded by Luwu.
LuwuAvailable in luwu/integration and gated by an FFlag. We anticipate this feature to be released and enabled by default in 0.1.0.
Needs the LuwuNonePrimitive FFlag.
flagged
LuwuNonePrimitive FFlag.none: noneThe value that means "intentionally empty". It's falsy like nil and equal only to itself, but a table can store it: assigning none keeps the key and an array holding it has no hole. typeof(none) and tostring(none) both give "none". The none Primitive explains when to use it.