tm.listeners
A tiny in-resource event bus. Shared. Nothing crosses a resource boundary: use events or exports for that.
lua
local function onChange(value) print(value) end
tm.listeners.add('volume', onChange)
tm.listeners.invoke('volume', 5) -- true (a listener existed), calls onChange(5)
tm.listeners.remove('volume', onChange)
tm.listeners.invoke('volume', 5) -- false| Function | Notes |
|---|---|
add(type, cb) | Registers cb for type. Adding the same function twice keeps one entry. |
remove(type, cb) | Removes it. Unknown names and functions are ignored. |
invoke(type, ...) | Calls every listener in registration order. Returns true when at least one existed. |
A listener that errors is logged with tm.log.error and skipped, so one bad listener never blocks the others. Listeners may add or remove listeners while an invoke is running: the run in progress is not disturbed.