Page 1 of 1

Hotloading module

Posted: Fri Jul 21, 2017 6:03 am
by clofresh
Hi!

I created a module that lets you reload your code on the fly without stopping your game. The code is on github

To set up a project to be hotloadable:

main.lua:

Code: Select all

require('module').load('game')
game.lua:

Code: Select all

local Module = require('module')
function M.hotload(prevState)
  val = 'hello'
end

function M.draw()
  love.graphics.print(val)
end

function M.keyreleased(key)
  if key == 'r' then
    Module.hotload()
  end
end

return M
Then you can try changing the val string to something else, and pressing 'r' in the game, and it will reload the code without having to stop the game!

There's a more detailed example in the repo.