lua-users home
lua-l archive

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


Hi everyone. I'd like to know if the following is possible. I have a function that returns multiple values. The first two are returned always, the others may or may be not present.
I'd like to do the following:
status, op, args = the_function()

with args being a table where the remaining values of the_function have been collected. I can't modify the_function to return additional values in a table, and I if possible I'd like to avoid collecting *all* returns in a table:
args = {the_function()}

This is my first approach, but it feels not quite right.

local function mySelector(...)
   local result1, result2
   result1 = select(1, ...)
   result2 = select(2, ...)
   local t = {...}
   table.remove(t, 1)
   table.remove(t, 1)
   return result1, result2, t
end

status, op, args = mySelector( the_function() )


Regards,
Ignacio Burgueño