Page 3 of 5

Re: Hot reload plugin that actually works?

Posted: Sat Jan 27, 2018 4:54 pm
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.

Re: Hot reload plugin that actually works?

Posted: Sat Jan 27, 2018 5:41 pm
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.

Re: Hot reload plugin that actually works?

Posted: Sat Jan 27, 2018 8:44 pm
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".

Re: Hot reload plugin that actually works?

Posted: Sun Jan 28, 2018 8:27 am
by hasen
Ok sounds interesting - and so did it work?

Re: Hot reload plugin that actually works?

Posted: Sun Jan 28, 2018 8:37 am
by pgimeno
I don't have Corona, but I know it won't.

Re: Hot reload plugin that actually works?

Posted: Sun Jan 28, 2018 9:36 am
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

Re: Hot reload plugin that actually works?

Posted: Sun Jan 28, 2018 9:39 am
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.

Re: Hot reload plugin that actually works?

Posted: Sun Jan 28, 2018 9:41 am
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.

Re: Hot reload plugin that actually works?

Posted: Sun Jan 28, 2018 10:07 am
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.

Re: Hot reload plugin that actually works?

Posted: Sun Jan 28, 2018 10:20 am
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.