Hello Guest it is July 16, 2019, 02:58:30 AM

### Author Topic: Here is a way to pass a Variable number of Params to a Lua function  (Read 2406 times)

0 Members and 1 Guest are viewing this topic.

#### poppabear

• 2,231
• Briceville, TN, USA
##### Here is a way to pass a Variable number of Params to a Lua function
« 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

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
« Last Edit: December 02, 2014, 02:55:27 PM by poppabear »
Commercial Mach3 & Mach 4, Design/Build/Retrofit CNC and Industrial machines.
http://www.ss-systems-llc.com/

#### BR549

• 6,874
##### Re: Here is a way to pass a Variable number of Params to a Lua function
« Reply #1 on: December 02, 2014, 07:04:44 PM »
Hya Scott, Can your method be used with a Mcodes  such as M701 . If so can you give an example (;-).

(;-) TP

#### BR549

• 6,874
##### Re: Here is a way to pass a Variable number of Params to a Lua function
« Reply #2 on: December 02, 2014, 09:38:56 PM »
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

#### poppabear

• 2,231
• Briceville, TN, USA
##### Re: Here is a way to pass a Variable number of Params to a Lua function
« Reply #3 on: December 03, 2014, 07:14:15 AM »
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
Commercial Mach3 & Mach 4, Design/Build/Retrofit CNC and Industrial machines.
http://www.ss-systems-llc.com/