AAtlas
Open navigation
Matcha/Functions/Lua base library

Lua base library

Matcha runs on a Luau-based VM, so the standard Lua(U) global functions are available and behave per the Lua 5.1 reference except where noted below. This page lists what the VM actually exposes and flags the Matcha-specific differences — it does not re-document standard Lua semantics.

Standard library surface

The following members are exposed in Matcha 1.0.0. Exposure confirms lookup only unless a section elsewhere in this reference describes verified behavior.

math

lua
math.abs       math.acos      math.asin      math.atan
math.atan2     math.ceil      math.clamp     math.cos
math.cosh      math.deg       math.exp       math.floor
math.fmod      math.frexp     math.huge      math.ldexp
math.log       math.log10     math.max       math.min
math.modf      math.noise     math.pi        math.pow
math.rad       math.random    math.randomseed
math.round     math.sign      math.sin       math.sinh
math.sqrt      math.tan       math.tanh

string

lua
string.byte      string.char      string.find      string.format
string.gmatch    string.gsub      string.len       string.lower
string.match     string.pack      string.packsize  string.rep
string.reverse   string.split     string.sub       string.unpack
string.upper

string.pack, string.packsize, string.split, and string.unpack are available Luau additions.

table

lua
table.clear     table.clone      table.concat     table.create
table.find      table.foreach    table.foreachi   table.freeze
table.getn      table.insert     table.isfrozen   table.maxn
table.move      table.pack       table.remove     table.sort
table.unpack

coroutine

lua
coroutine.close       coroutine.create      coroutine.isyieldable
coroutine.resume      coroutine.running     coroutine.status
coroutine.wrap        coroutine.yield

utf8

lua
utf8.char        utf8.charpattern    utf8.codepoint
utf8.codes       utf8.len            utf8.offset

bit32

lua
bit32.arshift    bit32.band       bit32.bnot       bit32.bor
bit32.btest      bit32.bxor       bit32.countlz    bit32.countrz
bit32.extract    bit32.lrotate    bit32.lshift     bit32.replace
bit32.rrotate    bit32.rshift

The bit32 library is available even when bitwise operator syntax is not desired.

buffer

lua
buffer.copy         buffer.create       buffer.fill         buffer.fromstring
buffer.len          buffer.readf32      buffer.readf64      buffer.readi8
buffer.readi16      buffer.readi32      buffer.readstring   buffer.readu8
buffer.readu16      buffer.readu32      buffer.tostring     buffer.writef32
buffer.writef64     buffer.writei8      buffer.writei16     buffer.writei32
buffer.writestring  buffer.writeu8      buffer.writeu16     buffer.writeu32

The audit confirmed that these buffer functions exist but did not invoke every function. Do not infer untested edge-case behavior from exposure alone.

vector

lua
vector              vector.abs          vector.angle       vector.ceil
vector.clamp        vector.create       vector.cross       vector.dot
vector.floor        vector.magnitude    vector.max         vector.min
vector.normalize    vector.sign

The vector library and these functions are exposed; their full semantics were not exercised by the safe audit.

os and debug

lua
os.clock       os.date        os.difftime    os.time
debug.info     debug.traceback

These functions are exposed. The safe audit did not invoke them.

Type & conversion

type

lua
function type(value: any): string

Standard. Roblox datatypes (Vector3, CFrame, …) and Instances all report as "userdata" — use typeof for the specific name.

tostring

lua
function tostring(value: any): string

Standard, and honors __tostring. Matcha formats Roblox datatypes differently from Roblox itself — tostring(Vector3.new(1, 2, 3)) returns "Vector3(1.0000, 2.0000, 3.0000)", not "1, 2, 3".

tonumber

lua
function tonumber(value: any, base: number?): number?

Standard. Trims surrounding whitespace, parses 0x hex, and accepts a base (2–36) — tonumber("ff", 16) returns 255. Returns nil if the value can't be parsed.

Iteration & varargs

pairs / ipairs / next

lua
function pairs(t: table): (function, table, any)
function ipairs(t: table): (function, table, number)
function next(t: table, key: any?): (any, any)

Standard iteration; ipairs stops at the first nil hole.

pairs does not honor the Luau __iter metamethod — it always iterates the raw table.

select

lua
function select(n: number | "#", ...): ...

Standard, including negative indices: select(-1, ...) returns the last argument.

unpack

lua
function unpack(t: table, i: number?, j: number?): ...

Returns t[i] through t[j] (defaults i = 1, j = #t). Exposed as a global — mainline Luau only provides table.unpack. unpack and table.unpack are separate function objects but behave identically.

Errors & protected calls

assert

lua
function assert(value: any, message: string?, ...): ...

Raises a catchable error (Matcha:<line>: <message>, or assertion failed! with no message) if value is falsy; otherwise returns its arguments unchanged — the way to raise a catchable error in Matcha.

pcall

lua
function pcall(f: function, ...): (boolean, ...)

Standard. Returns true plus f's results on success, or false, "Matcha:<line>: <message>" on a runtime fault.

xpcall

lua
function xpcall(f: function, handler: function, ...): (boolean, ...)

Standard, and forwards extra arguments to f (Luau-style): xpcall(fn, handler, 3, 4) calls fn(3, 4). On a real error, handler runs with the error message.

Metatables

setmetatable / getmetatable

lua
function setmetatable(t: table, mt: table?): table
function getmetatable(t: any): table | any

Standard. getmetatable returns the __metatable field when set; setmetatable on a table with a protected (__metatable) metatable raises cannot change a protected metatable.

newproxy

lua
function newproxy(addMetatable: boolean?): userdata

Lua 5.1 holdover, fully supported. Returns a blank userdata; with newproxy(true) it gets a fresh, settable metatable (retrieved via getmetatable), so metamethods like __index and __tostring work.

Raw access

rawget / rawset / rawequal / rawlen

lua
function rawget(t: table, key: any): any
function rawset(t: table, key: any, value: any): table
function rawequal(a: any, b: any): boolean
function rawlen(t: table | string): number

Standard. These bypass metamethods; rawset returns the table.

Memory

gcinfo

lua
function gcinfo(): number

Returns the VM's current memory usage in kilobytes.