lua-users home
lua-l archive

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


On 4/23/06, Norman Ramsey <nr@eecs.harvard.edu> wrote:
>     function output(...)
>       for i = 1, table.getn(arg) do --- can't use ipairs b/c arg might be nil
>         local v = arg[i]
>         assert(output_funs[type(v)], "Bad value to output()") (v)
>       end
>     end
>
> I am struggling to figure out how to implement this function in Lua 5.1.
> How am I to make sure that I get all the arguments when the new #
> operator is not specified when some arguments are nil?

The standard library function "select" is quite useful when dealing
with the ... expression.  For example:

 function output(...)
   for i = 1, select('#', ...) do
     local v = select(i, ...)
     assert(output_funs[type(v)], "Bad value to output()") (v)
   end
 end

Greg F