The module has no knowledge of Love's API, so the first step (in main.lua) is this:
Code: Select all
local Event = require 'event'
Event.injectDispatchers(love.handlers)
Event.injectDispatchers(love, { 'load', 'update', 'draw' })
Now instead of defining (for example) love.update, you can do something like this:
Code: Select all
Event.on('update', function (dt)
myGame:updateStuff(dt)
end)
If you need to unregister an event handler at some point, save the return value from Event.on and call :remove() on it later.
Code: Select all
local keyHandler = Event.on('keypressed', function (b, s, r)
myGame:mashButtons(b, s, r)
end)
-- later...
keyHandler:remove()
Code: Select all
Event.dispatch('pebkac', keyboard, chair)
https://gist.github.com/airstruck/9c07256b06ef5925c540