Optional Parameters in Handlers
Posted: Tue Mar 17, 2015 10:18 am
How would I go about using optional handler parameters? In LCS the Vec() function below would accept 2 or 3 parameters depending on how you pass them. I have tried the following:
If I only pass 2 arguments to Vec() the compiler complains even though z is declared as "optional".
Any ideas on the best approach? I would like to access the Vec() function from LCS and LCB to see if I can get some speed improvements.
Code: Select all
public handler Vec(in tX as Real, in tY as Real, in tZ as optional Real) as Array
variable tVec as Array
put the empty array into tVec
put tX into tVec["x"]
put tY into tVec["y"]
if tZ is not undefined then
put tZ into tVec["z"]
end if
return tVec
end handler -- Vec
private handler testVec() as Array
variable tVec as Array
put the empty array into tVec
-- put Vec(1,2) into tVec -- This throws compiler error "too few arguments"
put Vec(1,2,3) into tVec -- works OK
return tVec
end handler -- testVec
Any ideas on the best approach? I would like to access the Vec() function from LCS and LCB to see if I can get some speed improvements.