signal
Named events, available at xiao.signal. A callback is registered under a signal name and an identity. Registering the same identity again replaces its callback. Callbacks run in the order their identity was first added.
Signals are shared by every execution in the VM, so one script can fire a signal another script listens to. An error raised in a callback during xiao.signal.call goes back to the caller like any Lua error.
Functions
xiao.signal.add(name: string, identity: any, callback: function)
xiao.signal.add(name: string, identity: any, callback: function)
- Registers a callback under
nameandidentity. - Registering the same
identityagain replaces its callback.
xiao.signal.remove(name: string, identity: any): boolean
xiao.signal.remove(name: string, identity: any): boolean
- Returns
trueif the callback existed.
xiao.signal.get(name: string, identity: any): function | nil
xiao.signal.get(name: string, identity: any): function | nil
- Returns the callback or
nil.
xiao.signal.call(name: string, ...): any
xiao.signal.call(name: string, ...): any
- Calls every callback of
namewith.... - Stops at the first callback that returns a non-nil value and returns its values.
xiao.signal.connect(name: string, callback: function, identity: any)
xiao.signal.connect(name: string, callback: function, identity: any)
- Alias of
xiao.signal.add, other argument order.
xiao.signal.disconnect(name: string, identity: any): boolean
xiao.signal.disconnect(name: string, identity: any): boolean
- Alias of
xiao.signal.remove.
xiao.signal.connection(name: string, identity: any): function | nil
xiao.signal.connection(name: string, identity: any): function | nil
- Alias of
xiao.signal.get.
xiao.signal.fire(name: string, ...): any
xiao.signal.fire(name: string, ...): any
- Alias of
xiao.signal.call.
Events
Signals fired by the client:
A callback that raises an error while the client fires it is removed and the error is printed in the console.
local elapsed = 0
xiao.signal.add("think", "timer", function(dt)
elapsed = elapsed + dt
end)
xiao.signal.add("unload", "save", function()
xiao.fs.write("elapsed.txt", tostring(elapsed))
end)