Entry point
Starting a program from main with its drivers.
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.
Started from main
A Zig program starts from main. It registers the
drivers it uses and runs the reactive program built
from the root component. Because Zig has no closures, the root component is a named struct function.
pub fn main() !void {
Program.application(struct { pub fn run() void {
counter();
} }.run, &.{ console.driver() });
}
Zig suits low-level, allocation-explicit native code; the interface driver renders to a terminal. Otherwise the model is exactly the JavaScript entry point — a root component, a driver list, and a loop that turns only when a value is written.