erdos/src/async.lua

50 lines
1.0 KiB
Lua

ACTIVE = true
function __run(debug)
if love.event then
love.event.pump()
for n, a,b,c,d,e,f in love.event.poll() do
if n == 'quit' or not ACTIVE then
if not love.quit or not love.quit() then
ACTIVE = false
return a or 0
end
end
love.handlers[n](a,b,c,d,e,f)
end
end
local dt = 0
if love.timer
then dt = love.timer.step() or love.timer.getDelta()
end
if love.update then love.update(dt) end
if love.graphics and love.graphics.isActive() then
love.graphics.origin()
love.graphics.clear(0, 0, 0)
--if debug then love.graphics.rectangle('fill', 0,0, 10, 10) end
if love.draw then love.draw() end
love.graphics.present()
end
--if love.timer then love.timer.sleep(0.001) end
end
function await(fn)
while fn() ~= true do
if not ACTIVE then break end
__run()
end
end
function love.run()
if love.timer then love.timer.step() end
if love.getVersion() == 0
then
while ACTIVE do
__run()
end
else return __run
end
end