Part II · Profiles
11 Luau for Roblox
The profile for Roblox experiences: Luau's types and Roblox's, the class tree, the built-in library, and the files it writes.
Normative · Level 2Draft 0.1
11.1 Overview
Info
The profile with the id roblox turns graphs into Luau scripts for Roblox experiences, laid out as a Rojo project. It is the profile Roswaal was built for, and its library has 300 built-in nodes. Luau for Lune shares most of it.
11.2 Types and conversions
- Luau's own types:
number,string,boolean,table,function,thread, andnilas a value. - Roblox's datatypes, such as
Vector3,CFrameandColor3: 48 of them. - Every engine class, such as
PartandPlayer: 625 of them. - The one conversion:
numberandstring, both ways, as Luau converts them.
From a Luau annotation to a pin type
| Annotation | Pin type |
|---|---|
None, unknown, never | any |
A name, such as Model or Vector3 | That name |
A name with ?, such as Model? | That name; the pin is marked as possibly missing (§6.1) |
A dotted name, such as Module.Config | That name |
A table type, { … } | table |
| A union, a function type, anything else | any |
From pinTypeOf in core/nodes/variables.ts.
11.3 Families of Roblox's types
| Family | Types |
|---|---|
object | Every engine class. |
signal | RBXScriptSignal. |
table | table, and any written table type. |
function | function, and any written function type. |
value | Everything else: Luau's other types and Roblox's datatypes, RBXScriptConnection among them. |
On a type chip, RBXScript is left off the front of a name (RBXScriptConnection reads Connection), a written table type reads table and a function type function.
11.4 Classes and the hierarchy
The class tree, the classes' summaries and their members come from Roblox's Creator Documentation, generated into Roswaal's source by its build scripts rather than read at run time: 625 classes, 48 datatypes and 507 enums. Every class has one parent, up to Object at the root, and a class connects into any of its ancestors (§6.3).
11.5 The built-in library
| Category | Nodes | Runs on | Glyph |
|---|---|---|---|
| Flow | 20 | Both | flow |
| Events | 6 | Roblox only | events |
| Variables | 7 | Both | variables |
| Values | 11 | Both | values |
| Math | 15 | Both | math |
| Logic | 10 | Both | logic |
| Strings | 7 | Both | strings |
| Tables | 17 | Both | tables |
| Roblox Types | 108 | Both, and Roblox only | vector3 |
| Roblox | 12 | Roblox only | engine |
| Instances | 26 | Roblox only | instances |
| Players | 4 | Roblox only | players |
| Networking | 13 | Roblox only | networking |
| Modules | 10 | Both, and Roblox only | modules |
| Lune | 2 | Lune only | lune |
| Time | 8 | Roblox only | time |
| Threads | 16 | Both, and Roblox only | threads |
| Debug | 6 | Both | debug |
| Z-Up Conversions | 4 | Roblox only | conversions |
Generated from core/nodes and core/nodeGlyphs.ts. Both means the node works in a Lune graph too (§12). The Roblox Types category is split by datatype, each with a colour and a glyph of its own. A node that starts or ends a flow takes the glyph entry or terminal; Function and Declare Function take function, and Return return, whatever its category.
11.6 What each node compiles to
Every built-in node's page in these docs, such as Print, shows the Luau it compiles to. How values are bound and inlined is §7.2's rule, written as Luau: a value read once is written where it is read, and one read twice in a block becomes a local.
11.7 Scripts, modules, run contexts
| Script class | Run context | File written |
|---|---|---|
Script | absent, Server or Legacy | <name>.server.luau |
Script | Client | <name>.client.luau |
LocalScript | any | <name>.client.luau |
ModuleScript | any | <name>.luau |
Rojo decides what a file becomes in Studio from its name, so the class and run context are written into the name. A module returns what its Module Exports node is given. Where each file goes in the place is the node map's (§9.5), which becomes a Rojo project file.
The file's header
--!strict -- Generated by Roswaal. Do not edit this file directly; -- edit Main.nodescript and recompile instead. -- roswaal-graph: <the graph's id> -- roswaal-source: <a hash of the graph> -- roswaal-output: <a hash of what follows>
The first line is the graph's typecheck: --!strict, --!nonstrict, or no line for default. Then come the services the script uses, its requires, its types, its variables, its hoisted functions, its flow, and a module's return. Where the project asks and StyLua is installed, the file is formatted by StyLua.
11.8 Packs and hand-written Luau
- A pack is a
.nodedef.jsonfile, or a.nodedef.luaufile that returns a table: read as data, never run. - A pack's nodes compile with
expr,callorstatementtemplates (§10.5). - Graphs can hold hand-written Luau in a Code Block, a step, or a Luau Expression, a value. It is written into the program as it is.
11.9 Moonwave and comment tags
Proposed
-- comments so a Moonwave site still builds (§6.5). Not decided, and not built.