local coroutines = {} -- starts a coroutine and saves it for future reference function startcoroutine(co) assert(tostr(co) == "[thread]") -- make sure that co is a coroutine, the return value of cocreate() add(coroutines, co) end -- stops the the coroutine function stopcoroutine(co) del(coroutines, co) end function _coresolve() for co in all(coroutines) do if costatus(co) != 'dead' then assert(coresume(co)) else stopcoroutine(co) end end end -- to be used inside a coroutine function wait(seconds) wait_frames(seconds * 30) end -- to be used inside a coroutine function wait_frames(frames) for i = 1, frames do yield() end end