lua-users home
lua-l archive

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


On 06/11/2012 08:53, steve donovan wrote:
On Tue, Nov 6, 2012 at 9:50 AM, spir <denis.spir@gmail.com> wrote:
printf = function (fmt, ...)
    local strings = {}
    for i,elt in ipairs(arg) do
       strings[i] = tostring(elt)
    end
    write(format(fmt, unpack(strings)))
end

Watch out for that old-fashioned Lua 5.0 'arg' - LuaJIT does not like
it!  Besides you will not be able to process any nils in the argument.
Lua 5.2's table.pack() does the right thing, otherwise use the trick
in my example.

Thank you, again, Steve. I was aware there was some trap with arg, but did not remember what, or if it was important or not here. I'll have a look at "Lua 5.2's table.pack()". I guess you'd write maybe:
   args = pack(...)
to get a regular table from the tuple (or whatever internal representation the rest arg list has)? If yes (or close), i'll use that because it's clear for me, unlike the select(#, ...) syntax.

Denis