Logic Machine Forum
LUA compilation does not work? - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: LUA compilation does not work? (/showthread.php?tid=1025)



LUA compilation does not work? - puntukas - 04.10.2017

Hi all,
recently I faced a strange scripting behaviour: I can edit and save user library script (keep source, auto load), however this new version is not executed.
Somehow the old script version is executed. If I restart the server then the new version runs correctly.

However if I copy new functions from user library script into the resident script -all works correctly.

I spend hours checking scripting and can't understand what is wrong.



Any ideas?

thanks

(CPU model ARM926EJ-S rev 5 (v5l)


RE: LUA compilation does not work? - Erwin van der Zwart - 04.10.2017

Hi,

When you use automatic load on the lib container, all the functions are loaded and running into the background and only a reboot can refresh this loaded PID.

When you disable automatic load and call the functions into a event based script (with require('user.yourlib'), the functions are valid during that event execution,when you update the lib and run the event again, the require will reload the renewed user library. (just like your variables , they are also dropped after the event)

When you require the user lib inside a resident script and start the resident loop and when you change the user lib functions during run, the changes are not loaded until you restart the resident script. (just like your variables , they are kept during running resident event)

So in short, your user lib is only reloaded when a new script (program id) is started and that will trigger a new 'require' of the user lib, automatic load is loading only once the lib.

This is how the controller always have handled the user lib's and variables ..

BR,

Erwin


RE: LUA compilation does not work? - puntukas - 05.10.2017

Hi, Erwin,

thanks for the answer.
I have such structure:
resident script that runs every 60 seconds with require('user.modules').
So I suppose the user.modules is loaded every time I "require" thus they are compiled and run. But...I can changes "modules" code and nothing happens, "modules" runs the old code.
I can change resident script (changes are compiled), but required module that declared inside recompiled resident script isn't compiled.

P.S.
Erwin, thanks for Sonos script, unfortunately I failed to run door_bell.mp3 on my Sonos, but I will try harder Smile

Alius


RE: LUA compilation does not work? - admin - 05.10.2017

Library code is cached by Lua, calling require several times will not cause a reload.


RE: LUA compilation does not work? - puntukas - 05.10.2017

So how can I get edited modules that are loading from user library working?

Was it the same from the beginning? As I remember I could edit modules and they were loaded everytime with new edited code.

Thanks

Alius


RE: LUA compilation does not work? - admin - 05.10.2017

Nothing has changed. To fully reload a resident script disable then enable it again. Saving the script does not restart it (only code is refreshed) so libraries are not reloaded.


RE: LUA compilation does not work? - puntukas - 05.10.2017

(05.10.2017, 10:22)admin Wrote: Nothing has changed. To fully reload a resident script disable then enable it again. Saving the script does not restart it (only code is refreshed) so libraries are not reloaded.
Say I have resident script A and B that are using user library U. If I edit U and want new version to be loaded in A and B, I have to disable either A or B and enable to get U library reloaded? 

Is that correct?
Thanks,

A.


RE: LUA compilation does not work? - Erwin van der Zwart - 05.10.2017

Hi,

You need to restart them both as the user lib is loaded into the resident script at the start of that script.

When restarting a script only makes that script require the lib again, so the new lib is loaded only into that script, the script that has not been restarted will keep using the lib content it loaded when it started.

BR,

Erwin


RE: LUA compilation does not work? - puntukas - 06.10.2017

(05.10.2017, 21:26)Erwin van der Zwart Wrote: Hi,

You need to restart them both as the user lib is loaded into the resident script at the start of that script.

When restarting a script only makes that script require the lib again, so the new lib is loaded only into that script, the script that has not been restarted will keep using the lib content it loaded when it started.

BR,

Erwin

Thanks for the explanation!