I am migrating from Mach3 to Mach4 and have several M functions that need to be re-written to work with Mach4.  After looking at several code examples and DazTheGas videos (which are very informative)  my progress is still painfully slow.  ls there a primer for using the common functions called in Mach4 scripting and the general logic behind them?  In the absence of a primer, it would be helpful if the following code from the Lua examples was explained.  No need to explain what a function is, declaration of variables,  or the use of if then statements.  just what the functions are doing.  I see the function mc.mcGetInstance() used in a lot of Mach4 macros. I  assume that is polling some register and code execution depends of the result, but what are the possible results? 
The macros I use emulate  G77:  Variables are defined in Gcode for start and stop axis positions, feed rates, and cutting depth per pass.  A macro is then called which executes until the final depth is achieved.  Nothing major, but it does reduce code.
  
I am not looking to be taught how to fish, just to bait the hook. 
 
local inst = mc.mcGetInstance()
local a,b
function GCodeExecute(GCodeString)
   local rc = mc.mcCntlGcodeExecuteWait(inst, GCodeString) --This is the standard function call for executing gcode. it waits for motor feedback before continuing in the file.
   if rc ~= mc.MERROR_NOERROR then return "GCode failed", false end
end
a,b = GCodeExecute("G0 X1 Y2.5 Z3.5")
if b == true then
   mc.mcCntlSetLastError(inst, "Motion Succeeded")
else
   mc.mcCntlSetLastError(inst, a)
end
--You can even incorporate variables into the function call.
local travelxdistance = 1.45
a,b = GCodeExecute("G1 X"..travelxdistance.."Y0")--You can concatenate to the end of the gcode string using '..'
if b == true then
   mc.mcCntlSetLastError(inst, "Motion Succeeded")
else
   mc.mcCntlSetLastError(inst, a)
end