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 mode | Application mode | |
|---|---|---|
| Triggered by | no main | a function main / class App with function main |
| What runs | every top-level statement | declarations, then main |
| Top-level side effects | run | skipped — only main runs |
| Best for | scripts, learning | backend APIs, larger apps |
A simple function main
Define a top-level function main and Zornux starts there.
function main
show "Application started"
end
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.
class App
function main
show "Application started"
end
end
zornux run .
Starting a backend API
App.main is a good place to publish a web service.
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
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.
@entry
function launch
show "Application started"
end
Priority order
Zornux resolves the entry point in this order:
- the
entrysetting inzornux.project, when it names a class or function; - a function marked
@entry; - a
class Appwith afunction main; - a top-level
function main; - 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:
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
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.
function main with args
show "Hello " + item_at(args, 0)
end
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.
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
| Return | Exit code |
|---|---|
give back 0 / give back nothing / no return | 0 (success) |
give back N (0–255) | N |
| text, truth, list, non-whole, or negative | error ZX1909 |
| a whole number above 255 | error 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.
# 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.