lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Here's roughly the way I do it:

local event_coroutines = {}

function event_triggered(...)  -- called when an event is triggered
  local co = event_coroutines
  event_coroutines = {}
  for i = 1, #co do
    coroutine.resume(co[i], ...)
  end
end

function event_wait()
  event_coroutines[#event_coroutines + 1] = assert(coroutine.running())
  return coroutine.yield()
end