lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]



I'm not sure I understand your point.  In my mind, if I have two
functions returning 2 values, then I have 4 values plain and simple.  It
would be treated exactly the same as print(1,2,3,4).  Is there a reason
not to do it that way?
Hang on, unlike other languages a function can return different number of arguments depending on input. Now print isn't picky about arguments as it is just outputting them to std out. However, if you had a function that required x and y for some parabolic eqn, things could get messy if x relied on a fn that returned two values when x was negative.


local calcX

calcX = function(b)
   if b<0 then return calcX(-b),"Warning Negative Fixed" end
   else return math.sqrt(b) end
end

for x=-10,10 do
   plot(calcX(x),10)
end

You don't want returns mucking up input arguments