docs

You are reading the docs for v0.1.2. Nabi 0.1.2 is no longer supported. Latest release: v0.1.3 →

#3.13. reload:: - hot reload hooks and state

On this page

std::reload is what a program sees of hot reload under nabi dev (refs-lang 9.14): where a change applies, code that runs around it, and state that lives through it. Outside nabi dev point() returns at once, the hooks never run and a State is a plain box.

#3.13.1. active / point

active() is true while the program runs under nabi dev with its channel connected.

point() applies a change that is ready, on the calling thread. A change that keeps every type's layout applies as soon as it arrives; one that changes a layout applies at the first stop where no running frame or live value of old code depends on a changed type (refs-lang 9.14.4), and point() is where that usually holds. Call it where no local holds a value of a type you may edit: the top of a frame loop.

#3.13.2. on_reload / before_reload

on_reload(name, f) runs f after each change applies, before_reload(name, f) before it, both on the thread in point(), once per change. A hook registered again under the same name replaces the old one, so code that registers its hooks each time it runs does not stack them. While a before_reload hook is registered, every change waits for point(). Reload.functions may be empty when the compiler did not list them.

#3.13.3. State<T>

A State<T> keeps a value across changes to T's fields. The value lives in a box of its own behind a fixed cell, so a migration may rewrite or move it while a frame holds the State; copies of a State share the value. get returns a copy, set stores, update(f) stores f of the value.

A local of type T in a frame that keeps running (main's loop) holds a change to T back. Make the state in another function, so the loop only names State<T>:

nabi
fn main() {
    let state = new_state();
    loop {
        step(state);
        reload::point();
    }
}

fn new_state() -> reload::State<World> { reload::State::new(World::new()) }

#3.13.4. host_main

host_main() is the whole main of the program nabi dev builds and runs: it connects the channel (NABI_DEV), loads the first version of each hot package (NABI_DEV_PLUGINS, one path a line, dependencies first) with plugin::load and calls the function NABI_DEV_MAIN names in the last one. A load that fails prints the plugin error and exits with status 101. Programs do not call it themselves.

The runtime side is nabi_hot_* (active, connect, ready, point, events, hold).

Found a mistake? Edit this page on GitHub. Last updated