--///////////////////////////////////////////////////////////////////////// -- This is a lua version of a "C/C++" switch statment -- if you want a "default" case, you will need to add it -- Unlike "C/C++" Switch statements you can pass, and -- return values when you test against the switch's test var. -- It is in a Macro style form so you can play with it in the -- mcLua scripter. -- Have fun!, Poppa Bear --///////////////////////////////////////////////////////////////////////// function TestFunc() local val1 = 0; local val2 = 0; local val3 = 0; local inst = 0; local mInst = 0; local frc = 0;--function return code(is optional), 0=ok, -1 = error local par1 = "1"; local par2 = "2"; local par3 = "3"; --the above par1-3 are strings so they can be put in macherr directly inst = mc.mcGetInstance(mInst); local switch = { function(...)--the functions are vari-arg, so you can pass as many params as you want --local frc = 0; mc.mcCntlSetLastError(inst,"f1, param=nil, no return val"); --return frc; --(optional return value) end, function(...) local p1 = 0; local frc = 0; p1 = select(1, ...);--the select function will return all the arguments --you can use: select(#, ...); to return the number of args passed mc.mcCntlSetLastError(inst,"f2, p1="..p1.." frc= "..frc); return p1, frc; end, function(...) local p1 = 0; local p2 = 0; local frc = 0; p1, p2 = select(1, ...); mc.mcCntlSetLastError(inst,"f3, p1="..p1.." p2="..p2.." frc= "..frc); return p1, p2, frc; end, function(...) local p1 = 0; local p2 = 0; local p3 = 0; local frc = 0; p1, p2, p3 = select(1, ...); mc.mcCntlSetLastError(inst,"f4, p1="..p1.." p2="..p2.." p3="..p3.." frc= "..frc); return p1, p2, p3, frc; end }; CaseTestVarVal = 1;--The variable you test against, its value is also the table index value --Table indexes start at 1 (one), if you need to check against a 0 or negative, your going --to have to do some data manipulation --for a case that takes no parameters, you must pass a nil for it to work --you must set your switch case to a variable even if it does NOT return anything --In the above switch table you can also set the index to a case string like: --["case1"] = function() DoStuff; return stuff;end you would change your table index --in the call below to "case1" for example. frc = switch[CaseTestVarVal](nil); wx.wxSleep(1); CaseTestVarVal = 2; val1,frc = switch[CaseTestVarVal](par1); wx.wxSleep(1); CaseTestVarVal = 3; val1,val2,frc = switch[CaseTestVarVal](par1,par2); wx.wxSleep(1); CaseTestVarVal = 4; val1,val2,val3,frc = switch[CaseTestVarVal](par1,par2,par3); wx.wxSleep(1); mc.mcCntlSetLastError(inst," "); local breakpointvar = 0; end if (mc.mcInEditor() == 1) then TestFunc(); end