The Zuri Standard Library Zuri

Metaprogramming

zuri.watch

import zuri
Zuri

zuri exposes this as zuri.watch, so import zuri is enough and the names are called as zuri.watch.*. import zuri.watch reaches the same definitions directly.

How a program tells zuri run --watch about the files it depends on.

Watch mode restarts a program when a file it depends on changes. The runtime reports the Zuri source it reads by itself: the entry file, and every module imported from it, whether at the top of a file or inside a function, in any isolate. What the runtime can't see is a file that a library reads as data, when the program's behavior still depends on it, as wire reads templates. A library declares each such file with depends_on():

import json
import zuri.watch

def load_rules(path: string) {
  watch.depends_on(path)

  return json.decode(file(path).read())
}
Zuri

Outside watch mode, both functions return immediately without doing anything, so a library can call depends_on() every time, without checking active() first.

This module is imported separately from the rest of the zuri package, so that a library using it doesn't load the parser and the compiler as well.

Functions

depends_on()

zuri.watch.depends_on(path: string)
Zuri

Tells watch mode that this program depends on the file at path, so that a change to the file restarts the program.

Call it when you read the file. If the file is declared and then changed before watch mode has started watching it, the change is still noticed, because the file's contents are recorded along with its path. A path where there's no file yet is recorded too, and creating the file restarts the program.

Only the first declaration of a file is recorded, and declaring it again only costs a lookup, so a function can declare a file every time it reads it. Files in the standard library are never recorded, because they only change when Zuri itself is upgraded.

Parameters

  • path (string) — an absolute path, or one relative to the working directory.

Returns — bool: true if the program is running under zuri run --watch and the file was recorded, and false otherwise.

active()

zuri.watch.active() -> bool
Zuri

Whether this program is running under zuri run --watch.

Returns bool


2026, Richard Ore and Zuri contributors