lem is a simple event manager library that allows you to register and trigger events in your game / application.
It works the same way as NodeJS's EventEmitter.
local event = require "lem" --require the library
Create an event manager
local myEventManager = event:new()
Register an event listener
myEventManager:on('start', function ()
print("Starting game")
end)
Emit an event
myEventManager:emit('start')
You can also pass parameters in a table:
myEventManager:on('say', function (params)
print(params.message)
end)
myEventManager:emit('say', { message = "Hi!" })
The event manager object is passed through most of the methods. This allows you to chain function calls like so:
manager = event
:new()
:on('event1', function () print("event 1") end)
:on('event2', function () print("event 2") end)
Register an event listener
lem:on(eventname, callback)
//-> lem:addEventListener
Emit an event
lem:emit(eventname, params)
Remove an event listener
lem:remove(eventname, callback)
//-> lem:removeEventListener
Remove all listeners of a specific event
lem:reset(eventname)
//-> lem:removeEventListeners
Get total count of listeners
lem:getListenerCount(eventname)