@tilua-types/roblox
v4.0.0
Published
Luau and the whole Roblox API as tilua types: every class, enum, data type, service and global
Readme
@tilua-types/roblox
Luau and the whole Roblox API as tilua types: every class (921 of them), enum
(633), data type, service and global, plus what Luau adds to Lua — typeof,
buffer, bit32, utf8, table.create, string.split, math.clamp, ...
Luau is Roblox's language, so the two ship together. Underneath is
@tilua-types/lua, the Lua 5.1 standard library, which this depends
on and is loaded along with it — so this is the only package a Roblox project
installs.
npm i -D @tilua-types/roblox{ "types": ["roblox"], "paths": {}, "sourceMap": "sourcemap.json" }With sourceMap pointing at a Rojo sourcemap (rojo sourcemap -o sourcemap.json),
game, workspace and each file's script are typed from the real instance
tree, down to script.Parent.
What you get
- Classes with Roblox's own hierarchy. Every type is a nominal
declare class(Part extends FormFactorPart extends BasePart ...). APartpasses wherever aBasePartorInstanceis expected, but aFolderdoes not pass as aPart, and a table never passes as anInstance.typeof(instance)is"Instance". - Events with typed arguments. In
Players.PlayerAdded:Connect(function(player) ... end),playeris aPlayer. Callbacks assigned to a property, such asremote.OnServerInvoke = function(player, ...), are typed the same way. - Enums.
Enum.KeyCode.Eis anEnum.KeyCode,Enum.Materialworks as a type, and one enum's items do not pass as another's. - Data types with their operators.
Vector3 + Vector3,CFrame * Vector3and2 * vectorget their types from the declared metamethods. - Names checked against the API.
game:GetService("Players"),inst:IsA("BasePart")(which also narrows),Instance.new("Part")andFindFirstChildOfClass("Humanoid")all return the class they name, and a misspelt name is an error.
Deprecated members stay: Humanoid:LoadAnimation, Model:SetPrimaryPartCFrame
and the rest still run. Only the lowercase spellings from Roblox's early API
(findFirstChild, isA) are left out, since each is another name for a
member written the current way. Deprecated globals such as wait, spawn
and Workspace stay.
Errors in callbacks
A bundle's entry runs under xpcall, so an uncaught error names the project's
files, not lines of the bundle. A callback that Roblox runs later on its own
thread is outside that xpcall. This package's lowering (lowering.mjs) wraps
those callbacks in the same handler:
signal:Connect(f),signal:Once(f),signal:ConnectParallel(f)task.spawn,task.defer,task.delay, includingconst spawn = task.spawnRunService:BindToRenderStep,game:BindToClose,ContextActionService:BindActionandBindActionAtPriority
main.tilua:5: attempt to index nil with 'Name'
at main.tilua:5 (touched)
at main.tilua:7The error is still raised on the callback's thread, so the callback stops the
same way it did before. A callback that runs synchronously (a table.sort
comparator, names:map(f)) is not wrapped, because it is already inside its
caller's xpcall. coroutine is not wrapped either: coroutine.resume
returning false, err is part of how it behaves. Outside a bundle, nothing is
wrapped.
Where it comes from
index.d.tilua is generated. Don't edit it by hand; change
scripts/generate-roblox.mjs instead — or scripts/luau.d.tilua, the
hand-written Luau layer the generator copies into the head of the file. The generator converts the definitions
luau-lsp builds from the Roblox
API dump, at a pinned commit, into tilua syntax. To pick up a newer API:
npm run generate:roblox # the pinned commit
node scripts/generate-roblox.mjs --commit <luau-lsp commit> # a newer oneluau-lsp is MIT licensed. Its notice is in THIRD_PARTY_NOTICES.md.
