Notice the indentation in the code below. It REALLY helps the readability of the code and it keeps you from starring so long.

Also, although it is not required for a single expression, I like to wrap any expression in an if statement in parenthesis.
In a macro like M6, use mc.mcCntlGcodeExecuteWait() instead of the non wait function. You don't want to ever use mc.mcCntlGcodeExecuteWait() in a screen or button script but here in a macro script, it is what you want.
And remember (look at your line 22 "WAIT_MODE_Low"), all of the API functions and constants should be prefaced with mc. And case is important. It should be "mc.WAIT_MODE_LOW" instead of "WAIT_MODE_Low".
Line 3 improvement:
local inst = mc.mcGetInstance('M6 macro') -- This will allow logging the API calls with caller information.
Line 7 to 11 change. You don't have use the the interpreter to turn the spindle off. Use the API calls when you can in script!
If you have setup your ramp times in the spindle settings, they will be followed with the mc.mcSpindleSetDirectionWait().
locateSpindle, rc = mc.mcSignalGetHandle (inst, mc.OSIG_OUTPUT6) --Turn ON spindle lock.
rc = mc.mcSignalSetState(locateSpindle, 1) --Spindle lock ON
currentRPM, rc = mc.mcSpindleGetCommandRPM(inst) -- save the current RPM to restore later.
rc = mc.mcSpindleSetCommandRPM(inst, 15) -- use instead of execute M3 S15
--The possible values to use with the mc.mcSpindleSetDirectionWait() below
--mc.MC_SPINDLE_OFF
--mc.MC_SPINDLE_FWD
--mc.MC_SPINDLE_REV
rc = mc.mcSpindleSetDirectionWait(inst, mc.MC_SPINDLE_FWD)
-- Is there no input that tells you wen the keylock has engaged?
wx.wxSleep (5) --Wait 5 seconds
rc = mc.mcSpindleSetDirectionWait(inst, mc.MC_SPINDLE_OFF) --Turn OFF spindle.
18 to 25 became:
-- Compound statements like your line 21 do not work well with LUA functions that return multiple items. :(
-- Break it up like so. It makes the code easier to read and maintain in the future as well.
local hSig, state
hSig, rc = mc.mcSignalGetHandle (inst, mc.ISIG_OUTPUT5)
state, rc = mc.mcSignalGetState(hSig, mc.ISIG_OUTPUT5)
if (state == 1) then
rc = mcSignalWait(inst, mc.ISIG_INPUT5, mc.WAIT_MODE_LOW, 30) -- Wait on input 5 to go HIGH for at most 30 seconds.
-- Always put a timeout in you want to be able to catch errors instead of waiting indefinitely.
-- If you want to wait on the input to go high, use mc.WAIT_MODE_HIGH. Case is important!!!
-- you really want to check the return code from EVERY API call for success/failure.
-- Below will abort the script gracefully if there is an error.
if (rc ~= mc.MERROR_NOERROR) then
mc.mcCntlAlarm(inst, 100, "Timed out waiting for input 5 to go high.")
return(100) -- 100 here and above is just some number I dreamed up. you could plan your own error number scheme.
end
mc.mcSignalSetState(CarouselOut, 0)
end
52 to 59 became:
--PNP input 4 switch activated to turn OFF OUTPUT4
--To turn output4 off:
hSig = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT4);
state = mc.mcSignalGetState(hSig);
if (state == 1) then
mc.mcSignalSetState(CarouselRetract, 0)
else -- not 0
wx.wxMessageBox ("INPUT 4 not triggered OFF")
end