Hello Guest it is March 28, 2024, 01:06:34 PM

Author Topic: Lua interpreters  (Read 1332 times)

0 Members and 1 Guest are viewing this topic.

Lua interpreters
« on: March 19, 2018, 03:50:49 PM »
How much Lua interpreters run in Mach4?
As I check by module loading M-commands scripting and loading the same module in Screen load. Module loaded both even with check

if package.loaded.EWelder == nil then
    ew = require "EWelder"
    mc.mcCntlSetLastError(inst, "load_modules. EWelder loaded")
else
    mc.mcCntlSetLastError(inst, "load_modules. EWelder already loaded")
end

That is why question: there are two separate threads for UI and G-code execution? Or more. And where PLC script and Signal script executed, in UI thread?
Re: Lua interpreters
« Reply #1 on: March 20, 2018, 01:50:21 PM »
Hi,
yes there are two Lua chunks at runtime, of course only one can run at a time.

All of the separate scripts including Screen Load, Screen Unload, PLC and so on get pulled into one file and compiled.
The big file is called simply Lua Script. You have a read only version under Operator/Lua Script.

Craig
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'
Re: Lua interpreters
« Reply #2 on: March 20, 2018, 01:55:22 PM »
Quote
yes there are two Lua chunks at runtime, of course only one can run at a time.
- why only one at a time? Does this mean that M command execution freeze PLC script? As I assume this two interpreters run in separate threads, one - for UI and PLC staff, other - machine interpreter (MDI or File).
Re: Lua interpreters
« Reply #3 on: March 20, 2018, 02:05:32 PM »
Hi,
I'm not sufficiently confident that I can answer definitively. I think there is only one interpreter at it operates on one chunk at any given instant.

You can see this if you call a long running Gcode from a macro with mc.CntlGcodeExecuteWait() then the GUI will freeze until the code is finished at the the Lua
interpreter is free to run the GUI script again and update it.

Craig
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'
Re: Lua interpreters
« Reply #4 on: March 20, 2018, 02:42:02 PM »
This is very strange. I use script
Code: [Select]
function m101()
    if not ew.isMachineInSpotMode() then
        ew.onIncorrectCommand()
        return
    end
    ew.sigVars['tbToUp'] = 1
    repeat
        wx.wxMilliSleep(100)
    until (ew.sigVars['tbIsUp'] == 1) or not ew.isWorking()
end

if (mc.mcInEditor() == 1) then
    m101()
end
This script turn on table up valve and wait upper position responce. And it work! No freeze UI and it realy wait table upper position or machine stopped. If I disconnect position switch it wait infinitely, and UI responce OK.