Module signal
Signal management for Lua.
No dependency. Optional dependency: LÖVE to hook into LÖVE events.
Usage:
TODO
Module
| new () | Creates and return a new SignalRegistry. |
| event | SignalRegistry which will be used to bind signals that need to be called on game engine event; other ubiquitousse modules may bind to this registry if avaible. |
| registerEvents () | Call this function to hook signal.event signals to LÖVE events. |
SignalRegistry objects
| SignalRegistry.signals | Map of signals to list of listeners. |
| SignalRegistry:bind (name, fn, ...) | Bind one or several functions to a signal name. |
| SignalRegistry:unbind (name, fn, ...) | Unbind one or several functions to a signal name. |
| SignalRegistry:unbindAll (name) | Remove every bound function to a signal name. |
| SignalRegistry:replace (name, sourceFn, destFn) | Replace a bound function with another function. |
| SignalRegistry:clear () | Remove every bound function to every signal. |
| SignalRegistry:emit (name, ...) | Emit a signal, i.e. |
Module
- new ()
-
Creates and return a new SignalRegistry.
Returns:
- event
-
SignalRegistry which will be used to bind signals that need to be called on game engine event; other ubiquitousse modules may bind to this registry if avaible.
For example, every ubiquitousse module with a “update” function will bind it to the “update” signal in the registry; you can then call this signal on each game update to update every ubiquitousse module easily.
Provided signals:
update(dt), should be called on every game updatedraw(), should be called on every game draw- for LÖVE, there are callbacks for every LÖVE callback function that need to be called on their corresponding LÖVE callback
Type:
SignalRegistry - registerEvents ()
-
Call this function to hook signal.event signals to LÖVE events.
This means overriding every existing LÖVE callback. If a callback is already defined, the new one will call the old function along with the signal:emit.
Requires:
-
love
SignalRegistry objects
Signal registry.
A SignalRegistry is a separate ubiquitousse.signal instance: its signals will be independant from other registries.
- SignalRegistry.signals
-
Map of signals to list of listeners.
Type:
{["name"]={fn,...}} - SignalRegistry:bind (name, fn, ...)
-
Bind one or several functions to a signal name.
Parameters:
- name string the name of the signal
- fn function the function to bind to the signal
- ... function,... other function to bind to the signal
- SignalRegistry:unbind (name, fn, ...)
-
Unbind one or several functions to a signal name.
Parameters:
- name string the name of the signal
- fn function the function to unbind to the signal
- ... function,... other function to unbind to the signal
- SignalRegistry:unbindAll (name)
-
Remove every bound function to a signal name.
Parameters:
- name string the name of the signal
- SignalRegistry:replace (name, sourceFn, destFn)
-
Replace a bound function with another function.
Parameters:
- name string the name of the signal
- sourceFn function the function currently bound to the signal
- destFn function the function that will replace the previous one
- SignalRegistry:clear ()
- Remove every bound function to every signal.
- SignalRegistry:emit (name, ...)
-
Emit a signal, i.e. call every function bound to it, with the given arguments.
Parameters:
- name string the name of the signal
- ... arguments to pass to the functions bound to this signal