Hot reload plugin that actually works?

General discussion about LÖVE, Lua, game development, puns, and unicorns.
User avatar
pgimeno
Party member
Posts: 3548
Joined: Sun Oct 18, 2015 2:58 pm

Re: Hot reload plugin that actually works?

Post by pgimeno »

My point is that it is. Or rather, that it has too much power to allow covering all possible use cases. Also, see my edit.

Edit: If Corona can use loadfile and print, I could write a program for Corona that doesn't hot-reload properly.
hasen
Party member
Posts: 157
Joined: Sat Jan 20, 2018 2:01 pm

Re: Hot reload plugin that actually works?

Post by hasen »

pgimeno wrote: Sat Jan 27, 2018 4:54 pm My point is that it is. Or rather, that it has too much power to allow covering all possible use cases. Also, see my edit.

Edit: If Corona can use loadfile and print, I could write a program for Corona that doesn't hot-reload properly.
Well try it and get back to us. Otherwise it's just a hypothesis which may not be true. In any case hot reloading in 99% of cases (100%?) which seems to be how Corona works unless there's some complaints about that (which there may be) is way better than no hot reloading at all.
User avatar
pgimeno
Party member
Posts: 3548
Joined: Sun Oct 18, 2015 2:58 pm

Re: Hot reload plugin that actually works?

Post by pgimeno »

This works in lua, luajit and Löve. I guess it probably works in Corona too.

The program prints "hi" and waits for you to press enter, then prints "> hi" and keeps doing it every time you press enter. You can exit by typing an EOF (Ctrl+D in Linux and Mac, Ctrl+Z then enter in Windows) and then closing the window if you're in Löve.

The challenge is to press enter a few times, then modify module.lua changing the > to * and then keep pressing enter and see if the change of > to * was effective, without seeing a single line with just "hi" and no prefix (which would indicate a restart).

main.lua:

Code: Select all

local redefine_print = loadfile("module.lua")
local first = true

repeat
    print("hi")
    if first then
        redefine_print()
        first = false
    end
until io.read() == nil
module.lua:

Code: Select all

local orig_print = print

print = function(...)
    orig_print("> " .. tostring((...)), select(2, ...))
end
My prediction is that it will not change at all, meaning the file was not reloaded.

Redefining print() is a relatively common operation; often the aim is to add a timestamp at the beginning, or to redirect the output to a different place. Using loadfile() is not so common, but I predict that if it uses require() and it is hot reloaded, another problem will happen, namely that it will print "* > hi" instead of "* hi".
hasen
Party member
Posts: 157
Joined: Sat Jan 20, 2018 2:01 pm

Re: Hot reload plugin that actually works?

Post by hasen »

Ok sounds interesting - and so did it work?
User avatar
pgimeno
Party member
Posts: 3548
Joined: Sun Oct 18, 2015 2:58 pm

Re: Hot reload plugin that actually works?

Post by pgimeno »

I don't have Corona, but I know it won't.
gianmichele
Citizen
Posts: 63
Joined: Tue Jan 14, 2014 11:03 pm

Re: Hot reload plugin that actually works?

Post by gianmichele »

Corona doesn't do real "hot-reload". When you save a file, it just re-builds automatically the project from scratch.

Hot-reload of assets and code while the game is playing is much more difficult to handle. A good working example is Defold (which also has a lua debugger in its editor).

www.defold.com
hasen
Party member
Posts: 157
Joined: Sat Jan 20, 2018 2:01 pm

Re: Hot reload plugin that actually works?

Post by hasen »

pgimeno wrote: Sun Jan 28, 2018 8:37 am I don't have Corona, but I know it won't.
Well Corona is completely free. Well I tried it for you and you're right it didn't work "Attempt to call local 'redefine_print' (a nil value)" lol.
hasen
Party member
Posts: 157
Joined: Sat Jan 20, 2018 2:01 pm

Re: Hot reload plugin that actually works?

Post by hasen »

gianmichele wrote: Sun Jan 28, 2018 9:36 am Corona doesn't do real "hot-reload". When you save a file, it just re-builds automatically the project from scratch.

Hot-reload of assets and code while the game is playing is much more difficult to handle. A good working example is Defold (which also has a lua debugger in its editor).

www.defold.com
What's the difference in a practical sense? The project is instantly reloaded...seems pretty 'hot' to me.
User avatar
Tjakka5
Party member
Posts: 243
Joined: Thu Dec 26, 2013 12:17 pm

Re: Hot reload plugin that actually works?

Post by Tjakka5 »

hasen wrote: Sun Jan 28, 2018 9:41 am
gianmichele wrote: Sun Jan 28, 2018 9:36 am Corona doesn't do real "hot-reload". When you save a file, it just re-builds automatically the project from scratch.

Hot-reload of assets and code while the game is playing is much more difficult to handle. A good working example is Defold (which also has a lua debugger in its editor).

www.defold.com
What's the difference in a practical sense? The project is instantly reloaded...seems pretty 'hot' to me.
What Corona does is defined at 'Live Reloading'. Which can be pretty easy to setup with either Love or your Editor.
'Hot Reloading' on the other hand only reloads files that where changed, and maintains the state of the program, something that is difficult to achieve which has been explained earlier.
User avatar
pgimeno
Party member
Posts: 3548
Joined: Sun Oct 18, 2015 2:58 pm

Re: Hot reload plugin that actually works?

Post by pgimeno »

I think that hasen is talking about this plugin: https://marketplace.coronalabs.com/plug ... ive-coding
hasen wrote: Sun Jan 28, 2018 9:39 am Well Corona is completely free.
I don't run software I can't compile myself. It may be free as in beer, but not free as in freedom.

hasen wrote: Sun Jan 28, 2018 9:39 am Well I tried it for you and you're right it didn't work "Attempt to call local 'redefine_print' (a nil value)" lol.
It can't find the other file. Make sure it is placed somewhere where Corona can find it.
Post Reply

Who is online

Users browsing this forum: No registered users and 94 guests