lua-users home
lua-l archive

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


I suspect that 2 is the best (and probably the fastest) way to do this. If you really don't want to create a table, then try one of these:

function f1(...)
   local n = select("#", ...)
   local b
   b = function(i, f, ...)
       if f ~= nil then
           return false
       elseif i == n then
           return true
       end
       return b(i + 1, ...)
   end
   return b(1, ...)
end

function f2(...)
   for i = 1, select("#", ...) do
       if select(i, ...) ~= nil then
           return false
       end
   end
   return true
end




Tim Hunter wrote:
I have a varargs function. What is the Lua idiomatic way of determining if all the arguments are nil? I've thought of two ways:

1. #{...} == 0
2. next{...} == nil

This function is called very frequently, so I'd prefer not to have to create a table if I can avoid it.