Basic Reload
Each demo in this chapter is a sub-project with its own main.zolo and
separate modules. To run it, open the directory in a terminal and run zolo dev:
cd examples/features/21-hot-reload/01-basic-reload
zolo dev main.zolo
The entry point imports two functions from the greeter module and enters an
interactive read loop. The secret lies in how use greeter::{greet, farewell}
is compiled: every call goes through a live-binding thunk that re-resolves
the function in the module's export table — it never stores a fixed pointer.
Entry point: ENTER loop + import via live-binding.
// Feature: basic hot-reload
// Syntax: `zolo dev main.zolo` + edits to the `greeter` module.
// When to use: the "hello world" of `zolo dev` — edit-save-call flow.
//
// Press ENTER to call greet again. Edit greeter.zolo
// in the middle of the loop, save, press ENTER — you see the new code.
use greeter::{greet, farewell}
fn main() {
greet("zolo dev")
print("(edit greeter.zolo and save, ENTER to call again, 'q' to quit)")
while true {
let line = io::read("*l")
if line is nil || line == "q" {
break
}
greet("zolo dev")
}
farewell("zolo dev")
}
Requires the Zolo CLI/host — open in the playground or run locally.
The greeter module exposes both functions with pub fn. Edit the string inside
greet, save, and press ENTER — the new text appears immediately. The identity
of the export table is preserved (identity preserved), so any module that has
already imported it remains valid automatically.
Edit the message while the program runs; the next ENTER uses the new version.
// Feature: basic hot-reload — simple module
// Syntax: `pub fn name(...)` in an imported file.
// When to use: edit the function and see the new version without restart.
//
// Edit the string below, save, and the next call from main.zolo
// prints the new version. The `LuaState` stays the same — only the
// `greet` function is swapped in the `greeter` module's exports table.
pub fn greet(name: str) {
print("Hello, {name}! (edit this message and save)")
}
pub fn farewell(name: str) {
print("Bye, {name}.")
}
Requires the Zolo CLI/host — open in the playground or run locally.
Challenge
While the program is running, add a third function pub fn shout(name) to
greeter.zolo that prints in uppercase. Call it from main.zolo (just add
shout to the use) and save both files in sequence. Observe the order of the
reloaded: messages in the terminal.
See also