1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
//! The runtime's static globals: the JVM, the mods, the tables.
use crateRuntimeHandlers;
use crateRuntimeModuleRegistry;
use cratebuild_api_table;
use JavaVM;
use YogApi;
use HotReloader;
use LoadedModule;
use LazyLock;
use Mutex;
use OnceLock;
use RwLock;
// ── Static globals ────────────────────────────────────────────────────────────
/// Cached JVM handle for any-thread callbacks.
pub static JAVA_VM: = new;
/// Loaded mod libraries, keyed by mod id — owns the safe `dlopen`/`dlclose`
/// swap lifecycle (see `yog-hot-reload`) instead of a flat keep-alive `Vec`,
/// so a reload can find "the current generation of this mod" and safely
/// retire the previous one.
pub static HOT_RELOADER: =
new;
/// The mod currently inside its own `yog_mod_register` call. Every `api_*`
/// registration function reads this to tag what it stores with a
/// `LoadedModule` handle, instead of requiring mods to pass a mod id
/// through the stable C ABI (an ABI break, and edits to every mod's
/// source). Valid because a mod's entire registration always happens
/// synchronously inside one `yog_mod_register` call — see `load_mod_lib`
/// and, in dev builds, `trigger_hot_reload`.
pub static CURRENT_REGISTRATION: = new;
/// What the loaded `.yog`s say about their mods.
pub static MOD_INFOS: = new;
/// Stable api table. Mods capture this pointer at registration (yog-api's
/// `installed_mods()` calls through it later, e.g. from UI render) — so it
/// must outlive `nativeInit`, not live on its stack. `ctx` inside points at
/// `HANDLERS`' own `RwLock`, published *before* any mod registers, so it
/// stays valid for a hot-reload's later re-registration too.
pub static API_TABLE: = new;
/// All registered handlers + content. A `RwLock`, not a plain value: a
/// hot-reload appends a reloaded mod's entries after this has long been
/// published. Read sites (`handlers()`) take a read guard; registration
/// (initial or reload) takes a write guard — both deref straight through to
/// `RuntimeHandlers`.
pub static HANDLERS: = new;