Keywords
How each of Program's keywords is rendered into Zig.
Contents
How a Program becomes Zig, in parts. Start with the introduction, then follow each part into the rendered output and the runtime it links against.
- Introduction — what the Zig target is, and how to read the rest of this section.
- Capabilities — which high-level features are possible, built in or through a library.
- Example — a full program using every keyword, and the Zig it renders to.
- Naming considerations — how Program's dotted names are carried into Zig.
- Entry point — starting a program from
mainwith its drivers. - Drivers — the native drivers that provide the interface, console and network.
- Runtime — the Reactive and Context machinery the rendered code links against.
- Native modules — the hand-written Zig behind
NATIVEfunctions. - Keywords — how each of Program's keywords renders to Zig.
- Project setup — the files and commands to build and run the rendered program.
- Reserved words — the words Zig keeps for itself, and how a colliding name is escaped.
Program keywords in Zig
Each of Program's keywords maps to Zig. Names nest through struct containers joined
with . (see the example); because Zig has
no closures, a callback becomes a named struct function. Follow a keyword's own page for the full
rendering and the other targets.
| Keyword | Rendered Zig |
|---|---|
MODULE | A nested struct container, snake_case — Ui.Button.Integer becomes ui.button.integer. |
TYPE | A record becomes pub const Point = struct { x: f64, y: f64 };; a union becomes pub const Shape = union(enum) { circle: Circle, rect: Rect };. |
FUNCTION | pub fn Name(…) ReactiveValue(T) { … }. |
NATIVE | A pub fn whose body is the zig NATIVE string. |
INPUT | A parameter; a BINDING input is read and written. |
HOLE | A named struct { pub fn run(…) … }.run callback (Zig has no closures). |
LET | const name = …;. |
STATE | const name = Reactive.state(T, value);. |
REVERSE | A write-back whose closing SET is Reactive.set(state, value). |
WITH | module.with(name, replacement, struct { pub fn run() … }.run). |
See JavaScript keywords for the per-keyword detail and the modifiers; Zig differs in idiom (struct containers, struct-function callbacks) but the mapping is the same.