lua-users home
lua-l archive

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

The task is to write an iterator factory 'args' so that

   for k,v in args(...) do --[[whatever]] end

does the same as

   for k=1,select('#',...) do local v = select(k,...) --[[whatever]] end

It is quite easy by using a table, of course:

args = function(...)
  local t = table.pack(...)
  local n = t.n
  local i = 0
  return function()
    if i<=n then return i,t[i] end

It seems to be quite hard to do, even in the C API, without creating a
table. In fact, I have so far not succeeded.