The default love.run function in MoonScript

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
User avatar
Tesselode
Party member
Posts: 555
Joined: Fri Jul 23, 2010 7:55 pm

The default love.run function in MoonScript

Post by Tesselode »

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
Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests