To see the changes to your main.lua file live, add these lines to your love.update() function:
Code: Select all
if love.filesystem.load("main.lua") == nil then
love.timer.sleep(1)
love.filesystem.load("main.lua")()
end
Code: Select all
love .
Now when you make a change in the main.lua file and save, the running game will be updated. It doesn't reset the global variables, so it's great to code live. I use it for rapid prototyping.
What we do here in the code is to tell LÖVE if main.lua isn't available, wait a little and reload main.lua. It's a trick using a filesystem feature. When main.lua is saved, the old version of the file is removed for a moment before being replaced by the new version. I don't know if this works on Windows or Mac OS X though.
EDIT: I just realized that it's not about the filesystem, but about the text editor I use. I use vim for development, and vim seems to remove the old file when saving which causes LÖVE to throw an error. That's why I couldn't run only this line:
Code: Select all
love.filesystem.load("main.lua")()