Machsupport Forum

Mach Discussion => Mach4 General Discussion => Topic started by: learman on July 09, 2015, 09:47:45 AM

Title: converting Macro to Lua language
Post by: learman on July 09, 2015, 09:47:45 AM
Hello

I am working on converting one of my workstations from Mach3 to Mach4. Having trouble understanding the Lua scripting. Could someone take a look at this simple Macro and help convert it to Lua.

Thanks
Josh
Title: Re: converting Macro to Lua language
Post by: poppabear on July 09, 2015, 11:17:49 AM
Try this:

Code: [Select]
function m1002()
    local mInst         = 0;
    local inst          = mc.mcGetInstance(mInst);
    local NumValue      = 0;
    local hSig          = 0;
    local rc            = 0;
    local StringValue   = "";
    local state         = 0;

    --There is no rc error checking in this....
    hSig, rc = mc.mcSignalGetHandle(inst,mc.ISIG_INPUT2);
    state, rc = mc.mcSignalGetState(hSig);

    if (state == 0) then --0 is Input2 NOT active, 1 is Active
        --send error message to Machs error message box
        mc.mcCntlSetLastError(inst, "CHECK ENERGY MONITOR!!");

        --Optional send error message to a wx Message box
        --wx.wxMessageBox("CHECK ENERGY MONITOR!!");
    end
   
    local StopDebugVar = 0;
end

if (mc.mcInEditor() == 1) then
    m1002();
end

--have fun!
--Scott
Title: Re: converting Macro to Lua language
Post by: learman on July 09, 2015, 03:46:14 PM


I don't think i'm saving it properly. I have it saved in the profile i'm using under macros.

I also tried running one of the codes in the Luaexamples file with no luck.

Thanks for the help Scott!