lua-users home
lua-l archive

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


RLake@oxfam.org.uk wrote:
> >>
> >> function printf(file, fmt, ...) write(file, format(fmt, argfn())) end
> >> -- The argument fmt is only provided for documentation purposes --
> 
> > You can already do this with the 'unpack' function. For instance:
> 
> >  function printf(fmt, ...)
> >    write(format(fmt, unpack(arg)))
> >  end
> 
> Yeah, I know... I just thought it would be more cool (and faster) to not
> have to make a table and then unpack it.

Wouldn't this be easier?

  function printf(file, fmt, ...) write(file, format(fmt, ...)) end

That is, allow the dots as arguments that expand to the passed varargs.
The creation of the arg-table can be postponed until it is really
needed (or even made by hand: local arg={...}).

Ciao, ET.