Zornux docs
Get started Spec

Language

Application Entry Point

The smallest Zornux program is one line — show "Hello World!" — and it stays that way. As programs grow into backend APIs and structured apps, give them an explicit starting point: a function main, or a class App with function main. Nothing about the script model changes.

Two models, one language

Script modeApplication mode
Triggered byno maina function main / class App with function main
What runsevery top-level statementdeclarations, then main
Top-level side effectsrunskipped — only main runs
Best forscripts, learningbackend APIs, larger apps

A simple function main

Define a top-level function main and Zornux starts there.

zornux
function main
    show "Application started"
end
bash
zornux run app.zx

A structured class App

Put function main inside a class App. Zornux creates an App and calls its main — a natural home for application wiring, with access to the class's own fields and protected / private members.

zornux
class App

    function main
        show "Application started"
    end

end
bash
zornux run .

Starting a backend API

App.main is a good place to publish a web service.

zornux
controller Products at "/products"
    on GET "/"
        give back ok message "ok"
    end
end

web ProductAPI
    use Products
end

class App
    function main
        publish ProductAPI on port 5000
    end
end
bash
zornux serve .

Naming the entry explicitly — @entry

Mark any function with @entry to make it the starting point, overriding the conventional main (which then stays an ordinary function). It's the clearest way to say "start here" when the name isn't main.

zornux
@entry
function launch
    show "Application started"
end

Priority order

Zornux resolves the entry point in this order:

  1. the entry setting in zornux.project, when it names a class or function;
  2. a function marked @entry;
  3. a class App with a function main;
  4. a top-level function main;
  5. otherwise, script mode — top-level statements run in order.

Project entry and CLI flags

entry in zornux.project may name a class (App), a function (main), or a file (app.zx, the classic file convention). Two flags override resolution:

bash
zornux run .                     # auto-detect (App / main / script)
zornux run . --entry App         # force a named entry point
zornux run hello.zx --script     # force the script model, ignore any main
Only the entry point runs

In application mode an imported library's top-level statements don't run automatically — only the entry point does, so a program stays predictable as it grows. Zornux flags any skipped top-level statement with ZX1905 so you can move it into main.

Program arguments

main may take a single parameter named args — the command-line arguments passed after a bare --, as trusted text, in order.

zornux
function main with args
    show "Hello " + item_at(args, 0)
end
bash
zornux run app.zx -- Alice world     # args = ["Alice", "world"]

main may take no parameters or exactly one named args — anything else is ZX1908. The same works inside class App, and zornux debug and zornux serve accept the -- passthrough too.

Exit codes

main can give back a whole number from 0 to 255 as the process exit code — the natural way to signal success or failure to a shell or CI pipeline.

zornux
function main with args
    if length(args) is 0
        show "Please pass a name."
        give back 1
    end

    show "Hello " + item_at(args, 0)
    give back 0
end
ReturnExit code
give back 0 / give back nothing / no return0 (success)
give back N (0–255)N
text, truth, list, non-whole, or negativeerror ZX1909
a whole number above 255error ZX1910

A successful zornux run returns that code to the shell. Script-mode programs (no main) always exit 0.

Migrating from a script

You never have to — script mode stays supported. When you want an explicit entry point, wrap your top-level logic in main and leave declarations at the top level.

zornux
# before — script mode
create total = 4 + 5
show total

# after — application mode
function main
    create total = 4 + 5
    show total
end

Next: organize larger programs with Modules.