From 496e95a6c4d138e068ab7f6b23dc07f1257431e7 Mon Sep 17 00:00:00 2001 From: "kepler155c@gmail.com" Date: Sat, 26 Jan 2019 00:27:56 -0500 Subject: [PATCH] trigger event instead of os.queueEvent --- sys/apis/event.lua | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/sys/apis/event.lua b/sys/apis/event.lua index 2a66542..5fe4d87 100644 --- a/sys/apis/event.lua +++ b/sys/apis/event.lua @@ -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))