The default love.run function in MoonScript
Posted: Tue May 19, 2015 11:40 pm
For the two people out there who use MoonScript and need to customize love.run, here is the default love.run written in MoonScript. (GitHub)
Code: Select all
love.run = ->
if love.math
with love.math
.setRandomSeed os.time!
.random! for i = 1, 3
love.event.pump! if love.event
love.load arg if love.load
love.timer.step! if love.timer
dt = 0
--main loop
while true
--process events
if love.event
with love.event
.pump!
for e, a, b, c, d in .poll!
if e == "quit"
if not love.quit or not love.quit!
love.audio.stop! if love.audio
return
love.handlers[e] a, b, c, d
--update dt
if love.timer
with love.timer
.step!
dt = .getDelta!
--call update and draw
love.update dt if love.update
if love.window and love.graphics and love.window.isCreated!
with love.graphics
.clear!
.origin!
love.draw! if love.draw
.present!
love.timer.sleep 0.001 if love.timer