A tiny event module for Lua.
The event.lua file should be dropped into an existing project and required by it.
Event = require 'event'
Event = require 'event'
e = Event()
e:on('test', function(msg) print(msg) end)
e:dispatch('test', 'hello event')
-- print 'hello event'
Event with table instance
t = {}
function t:onTest(msg)
print('t onTest' .. msg)
nd
e:on('test_t', t.onTest, t)
e:dispatch('test_t', 'hello event')
-- print 't onTesthello event'
Handle events of type name
with callback
, instance
is an optional argument
Remove callback
Dispatch an event of type name
with optional arguments
Clear callbacks of type name
, if name
is nil, clear all callbacks