channels
A cross-component command bus for the editor shell. One component publishes an imperative interface — a small table of functions — under a name when it mounts and clears it when it tears down; another component looks the interface up by name and drives it. This is how the top bar opens dock panels, how the viewport camera asks whether its panel is open, and how the Window menu toggles the agent chat screen.
The registry is a module upvalue. A module loads once per VM, so the registry
lives for the VM's whole lifetime and is shared by every script that requires
this module — it survives hot-reload and edit↔play mode flips exactly as a
published handle must. Nothing is written to _G, so the sealed global table
stays untouched.
Exports
M.publish(name: string, iface: table)— publish an imperative interface under a name. A later publish with the same name replaces the prior one (hot-reload friendly).M.clear(name: string) -> boolean— remove a published channel; consumers'getreturnsnilafterward. Returnstrueif a channel was removed.M.get(name: string) -> table?— look up a published channel's interface by name, ornilif nothing is published under that name.
Usage
local Channels = require("@builtin::modules.api.editor.channels")
-- Publisher, at mount:
Channels.publish("editor_dock", { open = fn, close = fn })
-- Publisher, at destroy:
Channels.clear("editor_dock")
-- Consumer:
local dock = Channels.get("editor_dock")
if dock and type(dock.open) == "function" then dock.open("scene") end
Notes
- A cleared channel's
getreturnsnilrather than a handle into a dead component — consumers must toleratenilon every lookup. publishrequires a non-empty string name and a table interface; both raise on a bad argument.
Scoped to this part · feeds back into the world's score.