This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

LUA compilation does not work?
#1
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)
Reply
#2
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
Reply
#3
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
Reply
#4
Library code is cached by Lua, calling require several times will not cause a reload.
Reply
#5
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
Reply
#6
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.
Reply
#7
(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.
Reply
#8
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
Reply
#9
(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!
Reply


Forum Jump: