Posts: 38
Threads: 11
Joined: Jul 2017
Reputation:
0
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)
Posts: 1764
Threads: 6
Joined: Jul 2015
Reputation:
117
04.10.2017, 23:21
(This post was last modified: 04.10.2017, 23:23 by Erwin van der Zwart.)
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
Posts: 7769
Threads: 42
Joined: Jun 2015
Reputation:
447
Library code is cached by Lua, calling require several times will not cause a reload.
Posts: 38
Threads: 11
Joined: Jul 2017
Reputation:
0
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
Posts: 7769
Threads: 42
Joined: Jun 2015
Reputation:
447
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.
Posts: 1764
Threads: 6
Joined: Jul 2015
Reputation:
117
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