Machsupport Forum
Mach Discussion => Mach4 General Discussion => Mach4 Toolbox => Topic started by: poppabear on December 02, 2014, 02:43:14 PM
-
Here is a way to pass a Variable number of Params to a Lua function.
function VariableParamFunc(...)
local p1 = 0;
local p2 = 0;
local p3 = 0;
local mInst = 0;
local inst = mc.mcGetInstance(mInst);
p1, p2, p3 = select(1, ...);--this means start with the 1st param, and get
--all that is passed, in this case a max of three are passed, so p1-3
--receives them.
if p1 == nil then p1 = "nil"; end
if p2 == nil then p2 = "nil"; end
if p3 == nil then p3 = "nil"; end
mc.mcCntlSetLastError( inst,
"p1 = " .. tostring(p1)..
" p2 = ".. tostring(p2)..
" p3 = ".. tostring(p3));
end
if (mc.mcInEditor() == 1) then
VariableParamFunc();
VariableParamFunc(2,3,4);
end
--You can pass as many params as you want, by putting in the function
--variables that get them via the order them come in at.
--this example handles three.
The website screws up the formatting, so the file is attached.
Scott
-
Hya Scott, Can your method be used with a Mcodes such as M701 . If so can you give an example (;-).
(;-) TP
-
HIYA SCott, I think I found the answer to that question. In Mach4 you cannot use the ( ) for anything other than comments in Gcode. AND mach4 woul dhave to be modified to anything else.
Thanks , (;-) TP
-
Yes, it is only for using inside a script.
It cannot be used (at this time), in the MDI or G-Code,
but.... you can pass local #vars to a User Macro in the MDI or G-Code.
Scott