trigger event instead of os.queueEvent

This commit is contained in:
kepler155c@gmail.com 2019-01-26 00:27:56 -05:00
parent 66f9481e7d
commit 496e95a6c4
1 changed files with 15 additions and 0 deletions

View File

@ -243,6 +243,21 @@ local function processRoutines(...)
end
end
-- invoke the handlers registered for this event
function Event.trigger(event, ...)
local handlers = Event.types[event]
if handlers then
for _,h in pairs(handlers) do
if not h.co then
-- callbacks are single threaded (only 1 co per handler)
h.co = createCoroutine(h)
Event.routines[h.uid] = h
h:resume(event, ...)
end
end
end
end
function Event.processEvent(e)
processHandlers(e[1])
processRoutines(table.unpack(e))