Hot reload plugin that actually works?

General discussion about LÖVE, Lua, game development, puns, and unicorns.
hasen
Party member
Posts: 157
Joined: Sat Jan 20, 2018 2:01 pm

Hot reload plugin that actually works?

Post by hasen »

I've tried Lick and Lovedebug but they both don't seem to work very well. Lick works ok but it seems you have to add the require to every single lua file otherwise it will only react on changes to the main.lua, and when there is an error on reload it can never reload again forcing a manual relaunch anyway.

With Lovedebug I enabled the liveauto and all that happens is it says 'main.lua' reloaded..but the actual project doesn't seem to reload at all. Any real hot reload libraries out there so we can work like in Corona? Without this function I end up with 27 love projects open because I can't be bothered to close every one I launch for every little change.
User avatar
zorg
Party member
Posts: 3436
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Hot reload plugin that actually works?

Post by zorg »

See, the problem with hotswapping is that you need to commit to a somewhat rigid coding scheme in order for such a lib to work correctly; anything else would be wishful thinking.

If your hotswapping needs are because you want to test other lua files instantly without needing to reset your löve project (which is what i'm assuming), then what if you mistype something?
An error happens, so you need functionality to handle those, i.e. detect further hotswapping in the error handler itself (that can error again if another hotswap fails), and all of this shouts wrapping stuf in xpcall in tons of places.
And even with a successful hotswap, if your classes/lua files do load in correctly again, if you stored data in the one you just hotswapped, that will be gone, which may not have been what you have wanted.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
hasen
Party member
Posts: 157
Joined: Sat Jan 20, 2018 2:01 pm

Re: Hot reload plugin that actually works?

Post by hasen »

Hmm but everything you described works in the Corona simulator...so not sure why it would be so much different in Love2d. What do you normally do then - just keep opening and closing Love2d every time you want to test something after a code change?
User avatar
Sir_Silver
Party member
Posts: 286
Joined: Mon Aug 22, 2016 2:25 pm
Contact:

Re: Hot reload plugin that actually works?

Post by Sir_Silver »

That's what I do. I use Visual Studio Code with the LOVE extension which allows me to run my project by just pressing alt + l. I used to drag my project folder onto the love.exe to get it to run. :P
User avatar
zorg
Party member
Posts: 3436
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Hot reload plugin that actually works?

Post by zorg »

hasen wrote: Fri Jan 26, 2018 12:45 pm Hmm but everything you described works in the Corona simulator...so not sure why it would be so much different in Love2d. What do you normally do then - just keep opening and closing Love2d every time you want to test something after a code change?
Usually, yes; although i have written my own hotswap lib as well, but it would only work for that one project, because of how intertwined it needed to be with code.

I am curious though about corona's way of doing it; i tried to search for it on their reference website, but couldn't find anything called "swap" or "reload" that was relevant; care to link what you were referring to? (It may have been a function of the editor itself, since i did read about breakpoints and whatnot; löve doesn't come with an editor, but ZeroBrane can do much of that stuff if correctly configured)

Alternatively, i only found references to "Corona Simulator Console" in the reference docs, but only in reference to errors being printed to a console (whether Sublime Text's through a plugin or not), and löve can already write to a console (on windows, with using lovec.exe instead of love.exe) and it will also show traceback info when it errors, by showing the baby-blue screen of death.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
hasen
Party member
Posts: 157
Joined: Sat Jan 20, 2018 2:01 pm

Re: Hot reload plugin that actually works?

Post by hasen »

Sir_Silver wrote: Fri Jan 26, 2018 1:11 pm That's what I do. I use Visual Studio Code with the LOVE extension which allows me to run my project by just pressing alt + l. I used to drag my project folder onto the love.exe to get it to run. :P
Ok I see. Yes I use Atom with the Love IDE and it has the same kind of thing. Certainly so much quicker than launching the game each time in something like Unity or Gamemaker but still not quite as convenient as Corona.
hasen
Party member
Posts: 157
Joined: Sat Jan 20, 2018 2:01 pm

Re: Hot reload plugin that actually works?

Post by hasen »

zorg wrote: Fri Jan 26, 2018 2:06 pm
hasen wrote: Fri Jan 26, 2018 12:45 pm Hmm but everything you described works in the Corona simulator...so not sure why it would be so much different in Love2d. What do you normally do then - just keep opening and closing Love2d every time you want to test something after a code change?
Usually, yes; although i have written my own hotswap lib as well, but it would only work for that one project, because of how intertwined it needed to be with code.

I am curious though about corona's way of doing it; i tried to search for it on their reference website, but couldn't find anything called "swap" or "reload" that was relevant; care to link what you were referring to? (It may have been a function of the editor itself, since i did read about breakpoints and whatnot; löve doesn't come with an editor, but ZeroBrane can do much of that stuff if correctly configured)

Alternatively, i only found references to "Corona Simulator Console" in the reference docs, but only in reference to errors being printed to a console (whether Sublime Text's through a plugin or not), and löve can already write to a console (on windows, with using lovec.exe instead of love.exe) and it will also show traceback info when it errors, by showing the baby-blue screen of death.
Looks like you updated your post since my reply. Yes it's Corona's simulator for testing the code. The Love2d doesn't have this unfortunately. It hot reloads for any change at all, even adding an image file into the project directory (or indeed removing one). I guess that's why they advertise on their site that Corona is the only 2D engine with hot reload.
User avatar
zorg
Party member
Posts: 3436
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Hot reload plugin that actually works?

Post by zorg »

(I only added to it once, before any other reply appeared under it, hence why it doesn't have the "modified: ..." line at the bottom of it. :P )

To be fair, Löve's a framework, not an engine; it doesn't give you an IDE, nor makes you use stuff that people could design for themselves to suit their own workflow, like Scene/Node managers and stuff like that.

But as i said, others have come up with solutions for that, ZeroBrane being a very throughout IDE for lua and for Löve.

That said, you can implement simpler hot reloading methods, like (if you have all init code in love.load, then) calling love.load again, for example (with or without having some cleanup code that might be ran), or extending that with using xpcall on love.update and love.draw, for example (and also the love.event part) and you'll need to define an error handler that continuously parses the file that errored for modification by comparing the modified file date with the one you saved somewhere as a variable; but even those might not capture all errors and even if they did, it may not gracefully continue running after the errors were corrected, since it does need to reload files, not just functions, and files can have tons of code that may affect what changes between hotswaps; even an "impossible" scenario might happen that you couldn't get to from starting your project anew.

IMHO, one would be better off coding what they want, rather than wasting time on trying to code a well-working generic hotswapping module. If it's only for content, like images and sounds, then that's easier to implement correctly.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
hasen
Party member
Posts: 157
Joined: Sat Jan 20, 2018 2:01 pm

Re: Hot reload plugin that actually works?

Post by hasen »

zorg wrote: Fri Jan 26, 2018 5:20 pm (I only added to it once, before any other reply appeared under it, hence why it doesn't have the "modified: ..." line at the bottom of it. :P )
Yeah I confused you with Sir_Silver it seems.
zorg wrote: Fri Jan 26, 2018 5:20 pm To be fair, Löve's a framework, not an engine; it doesn't give you an IDE, nor makes you use stuff that people could design for themselves to suit their own workflow, like Scene/Node managers and stuff like that.
How is that different from Corona? Corona has no IDE either.
zorg wrote: Fri Jan 26, 2018 5:20 pm But as i said, others have come up with solutions for that, ZeroBrane being a very throughout IDE for lua and for Löve.

That said, you can implement simpler hot reloading methods, like (if you have all init code in love.load, then) calling love.load again, for example (with or without having some cleanup code that might be ran), or extending that with using xpcall on love.update and love.draw, for example (and also the love.event part) and you'll need to define an error handler that continuously parses the file that errored for modification by comparing the modified file date with the one you saved somewhere as a variable; but even those might not capture all errors and even if they did, it may not gracefully continue running after the errors were corrected, since it does need to reload files, not just functions, and files can have tons of code that may affect what changes between hotswaps; even an "impossible" scenario might happen that you couldn't get to from starting your project anew.

IMHO, one would be better off coding what they want, rather than wasting time on trying to code a well-working generic hotswapping module. If it's only for content, like images and sounds, then that's easier to implement correctly.
Well it seems to work perfectly in Corona anyway. Maybe it will be added in the future who knows.
User avatar
zorg
Party member
Posts: 3436
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Hot reload plugin that actually works?

Post by zorg »

As with GUI and Scene managers, only as a 3rd party library, if we're to be honest.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
Post Reply

Who is online

Users browsing this forum: No registered users and 52 guests