## Hot reload plugin that actually works?

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

### Re: Hot reload plugin that actually works?

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.
Thrust II Reloaded - GifLoad for Löve - GSpöt GUI - My NotABug.org repositories - portland (mobile orientation)
The MS-Github repositories I had have been closed after the acquisition announcement and will be removed in the near future.

hasen
Party member
Posts: 157
Joined: Sat Jan 20, 2018 2:01 pm

### Re: Hot reload plugin that actually works?

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.

pgimeno
Party member
Posts: 1377
Joined: Sun Oct 18, 2015 2:58 pm

### Re: Hot reload plugin that actually works?

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

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".
Thrust II Reloaded - GifLoad for Löve - GSpöt GUI - My NotABug.org repositories - portland (mobile orientation)
The MS-Github repositories I had have been closed after the acquisition announcement and will be removed in the near future.

hasen
Party member
Posts: 157
Joined: Sat Jan 20, 2018 2:01 pm

### Re: Hot reload plugin that actually works?

Ok sounds interesting - and so did it work?

pgimeno
Party member
Posts: 1377
Joined: Sun Oct 18, 2015 2:58 pm

### Re: Hot reload plugin that actually works?

I don't have Corona, but I know it won't.
Thrust II Reloaded - GifLoad for Löve - GSpöt GUI - My NotABug.org repositories - portland (mobile orientation)
The MS-Github repositories I had have been closed after the acquisition announcement and will be removed in the near future.

gianmichele
Prole
Posts: 44
Joined: Tue Jan 14, 2014 11:03 pm

### Re: Hot reload plugin that actually works?

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?

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?

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.

Tjakka5
Party member
Posts: 236
Joined: Thu Dec 26, 2013 12:17 pm

### Re: Hot reload plugin that actually works?

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.
Check out my portfolio: http://tjakka5.sorunome.de/

pgimeno
Party member
Posts: 1377
Joined: Sun Oct 18, 2015 2:58 pm

### Re: Hot reload plugin that actually works?

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.
Thrust II Reloaded - GifLoad for Löve - GSpöt GUI - My NotABug.org repositories - portland (mobile orientation)
The MS-Github repositories I had have been closed after the acquisition announcement and will be removed in the near future.

### Who is online

Users browsing this forum: No registered users and 5 guests