Q:

Lua process vararg in function process only 1st parameter

I'm trying to get a bit tricky logging, but can't get why ... processing only 1st parameter in a function called
I have this function
local logger = function (name, ...)
    -- Expected table processing here, but no.
    print("[" .. name .. "] log called with " .. ...)
end

return setmetatable({}, {__index = function(self, name)
    local log = function(...)
        return logger(name, ...)
    end
    self[name] = log
    return log
end})

And how it's called
local testf = require "test_log"["TestA"]

testf("TestB", "TestC")
testf("TestC", "TestB")

But getting back this result
[TestA] log called with TestB
[TestA] log called with TestC

The problem I can't get 2nd (and further) parameters from testf function and can't get why.
Thanks in advance!

A:

Your code uses only first parameter
local s = ''
for i=1,select('#',...) do s = s .. select(i, ...) end
print("[" .. name .. "] log called with " .. s)

Also, you can use s = table.concat({...}), but it will produce different results in cases where vararg contains nil values

