Targets · Zig · Entry point

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.

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.