Loomreference

Luau globals

The Luau standard library a previewed tree runs against, and what is missing on purpose.

roblox-ts code calls Luau’s globals with no import: table.insert, math.clamp, 1-based string indices. Loom defines the whole standard library on globalThis before your first component runs, on the dev server and in a static build.

What is installed

GlobalMembers
tableinsert, remove, find, concat, sort, create, clear, clone, freeze, isfrozen, pack, unpack, move, and the deprecated getn, maxn, foreach, foreachi
stringlower, upper, len, reverse, char, byte, sub, rep, split, find, gsub, match, gmatch, format
mathabs, floor, ceil, sqrt, max, min, pow, exp, sin, cos, tan, asin, acos, atan, atan2, sinh, cosh, tanh, log, log10, ldexp, frexp, modf, sign, clamp, round, fmod, deg, rad, noise, random, randomseed, huge, pi
osclock, time, difftime, date
bit32band, bor, bxor, bnot, btest, lshift, rshift, arshift, lrotate, rrotate, extract, replace, countlz, countrz, byteswap
utf8char, codepoint, len, offset, charpattern, nfcnormalize, nfdnormalize
debugtraceback, profilebegin, profileend, setmemorycategory, resetmemorycategory, info
buffercreate, fromstring, tostring, len, the readi8…readf64 / writei8…writef64 pairs, readstring, writestring, copy, fill
taskspawn, defer, delay, cancel, wait, on browser timers
coroutinecreate, resume, yield, wrap, status, running, isyieldable, close
RandomA seeded generator with NextInteger, NextNumber, NextUnitVector, Clone
DateTimenow, fromUnixTimestamp, and the format and component readers
Free functionsselect, unpack, rawget, rawset, rawequal, rawlen, typeOf, typeIs, pcall, xpcall, pairs, ipairs, next, tostring, tonumber, error, warn, print, assert, tick

tostring, string concatenation and print format numbers as Luau does (%.14g). 0.1 + 0.2 reads 0.3, and 100 / 3 reads 33.333333333333.

typeOf answers "Font" for a Font and "buffer" for a buffer, so typeIs checks on them work.

table counts from 1

table.* functions take Luau’s 1-based indices. roblox-ts passes the number in your source straight through, and loom reads it as Luau would.

The array methods roblox-ts compiles as macros stay 0-based. These two lines remove the same element:

list.remove(0); // the macro: 0-based, like TypeScript
table.remove(list, 1); // the library: 1-based, like Luau

string.find works the same way.

Tables are ordinary JavaScript values: an array, a Map, a Set or a plain object. #list is list.length, and a hole doesn’t end it.

sort takes a predicate

Luau’s comparator answers “does a come first?”, not “which is bigger?”:

table.sort(rows, (a, b) => a.order < b.order); // boolean, not -1 / 0 / 1

A JS-style comparator returning a number is truthy for both -1 and 1, so it doesn’t sort. With no comparator, the order is <, as in Luau. Array.prototype.sort also accepts the boolean predicate, so a roblox-ts .sort() orders correctly.

Where loom is forgiving

The engine throws in each of these. Loom keeps the preview rendering instead:

CaseRobloxLoom
insert at an out-of-range positionerrorclamps into range
remove at an out-of-range positionerrorreturns nil, changes nothing
concat over a non-string, non-number elementerrorruns it through tostring

freeze is Object.freeze. It stops writes to an array or a plain object, but not Map.set or Set.add.

string patterns and tuple returns

find, match, gmatch and gsub take Luau patterns: every character class (%a, %c, %d, %g, %l, %p, %s, %u, %w, %x and their upper-case complements), anchors, quantifiers, captures and %1–%9 back-references. Indices are 1-based, and find accepts a negative init that counts back from the end.

The classes are ASCII, as in the engine: é is not %a, and %s is the six ASCII space characters. A string with no pattern characters, such as string.find(path, "/"), is a plain search.

find, match and gmatch return captures as the array roblox-ts reads a LuaTuple as, and an empty array when nothing matches. find returns start, end and then every capture, so const [s, e, key] = string.find(…) reads the key:

const [start, finish] = string.find(label, "%d+");
const [name] = string.match(path, "([^/]+)$");
for (const [word] of string.gmatch(sentence, "%a+")) { /* … */ }

gsub takes a function or a table as its replacement, as well as a string. format supports width, padding and precision.

string.gsub("a b", "%a", (c) => c.upper()); // "A B", 2
string.gsub("a b", "%a", { a: "X", b: "Y" }); // "X Y", 2
string.format("%02d:%05.1f | %-10s|", 7, 3.14159, "ab");

Methods on strings and arrays

roblox-ts also calls these on a string. String.prototype has .lower(), .upper(), .sub(), .rep(), .find(), .gsub(), .format(), .gmatch(), .byte(), .len(), .reverse() and .size(). Each calls the library above, with the same 1-based indices and tuple returns. .sub() replaces the legacy HTML method JavaScript ships under that name.

.match() is not patched on the prototype, because JavaScript’s own match is shared by the whole page. Instead, the plugin rewrites .match() calls in your source: on a string with a pattern it is Luau’s string.match, and a RegExp argument keeps the JS method. .split() stays native.

Array.prototype has the roblox-ts macros .size(), .isEmpty(), .remove(i), .unorderedRemove(i) and .clear(), 0-based. .size() and .isEmpty() also work on Map and Set in your source, through the same rewrite. Every other Map on the page keeps plain JS behavior. See source transforms.

math.randomseed really seeds

randomseed switches math.random to a deterministic generator. A scene that seeds gets the same “random” layout on every reload.

math.log takes an optional base. frexp and modf return their pair as an array you can destructure.

os.date

A strftime subset: %a %A %b %B %c %d %H %I %j %m %M %p %S %x %X %y %Y %%. An unknown specifier is left as written. The *t and !*t table forms and the ! UTC prefix work with any format. os.time accepts a date table or no argument, and os.difftime subtracts two of its results.

debug profiling shows up in devtools

debug.profilebegin and profileend call performance.mark and performance.measure, so existing instrumentation shows up in the browser’s Performance panel. debug.traceback returns the JavaScript stack.

bit32 and buffer details worth knowing

bit32 uses Luau’s shift rules. A shift of 32 or more gives zero, where JavaScript’s << shifts by count % 32. Every result is an unsigned 32-bit number.

buffer is little-endian and bounds-checked. An out-of-range access throws, as in the engine.

The stubs

These exist so the code runs, and do nothing useful:

GlobalWhat it does
math.noiseReturns 0 for every input.
debug.infoReturns an empty tuple, so callers destructure nils instead of crashing.
debug.setmemorycategory resetmemorycategoryNothing.
task.waitReturns a Promise, so await task.wait(n) works. A bare synchronous task.wait() doesn’t block.

What is deliberately absent

MissingWhy
setmetatable, getmetatable, newproxyYour classes are JavaScript classes. Faking __index would mean proxying every table in the program.
print in the type declarationsprint works at runtime. It is left out of the ambient declarations because lib.dom already declares one. See TypeScript setup.
Filtering and networkingAnything that needs a Roblox server throws by name, such as HttpService.GetAsync and TextService.FilterStringAsync. See Services.