local coroutines={} -- starts a coroutine and saves it for future reference function startcoroutine(fn) assert(tostr(fn) == "[thread]") -- make sure that fn is a coroutine, the return value of cocreate() add(coroutines, fn) end -- stops the the coroutine function stopcoroutine(fn) del(coroutines, fn) 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