733
« on: June 01, 2017, 01:46:18 AM »
Reinhard,
LUA is not multi-threaded as there is nothing protecting the global data tables. So each instance runs in its' own space (with its' own global data and message loop, etc...). Each LUA panel has one instance of LUA associated with it. You can share code between the instances by requiring a module. But the global data of one instance cannot be accesses from one instance to the next, etc... So storing the address of a module table variable from one instance in a register and trying to use it in another instance will lead to "bad news". The only really safe way to share data across LUA instances is with the Mach registers (because these registers are thread safe and mutexed).
In Mach, these are the LUA instances:
1. One instance for the GUI (runs the screen scripts)
2. One instance for the mcLua macro script plugin. (runs M codes)
3. One instance for the PMC (runs the ladder code)
4. And one instance per LUA panel in the GUI.
All of these instances have access to the MachAPI functions.
Only the GUI has access to the ScreenAPI functions.
Steve