Events
A simple named-event bus: subscribe, emit and unsubscribe.
Namespace: caffeine.events
on#
Lua: caffeine.events.on
text
on(eventName, callback) -> integer
Subscribes a callback to a named event.
| Parameters | Type | Description |
|---|---|---|
eventName | string | Event name. |
callback | function | Called with the arguments given to emit. |
Returns: integer. Handler handle for off.
Example
lua
local h = caffeine.events.on('hit', function(dmg) end)
emit#
Lua: caffeine.events.emit
text
emit(eventName, ...)
Calls every handler of the event in registration order. A handler error is logged and does not stop the others.
| Parameters | Type | Description |
|---|---|---|
eventName | string | Event name. |
... | any | Arguments passed to each handler. |
Returns: none
Example
lua
caffeine.events.emit('hit', 10)
off#
Lua: caffeine.events.off
text
off(handle)
Removes a handler.
| Parameters | Type | Description |
|---|---|---|
handle | integer | Handle returned by on. |
Returns: none
Example
lua
caffeine.events.off(h)