lua-users home
lua-l archive

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


I was also thinking about such things. I don't like the idea of making #... return the number of arguments. I'm thinking about something like this:

function f1(args...)  -- variable parameters tuple named 'args'
  for i = 1, #args do
    print(args[i])
  end
  args[1] = 5  -- why not?  (out-of-bound case would generate an error)
return args... -- using the tuple name followed by "..." expands it into all values -- "return args" or print(args) would issue a syntax error, because 'args' isn't a real variable
end

Now, this can be expanded further:

function f2()
  local r... = pcall(f1)
  if not r[1] then
    print("error: "..r[2])
  end
  return r...
end

--
Best regards,
Sergey Rozhenko                 mailto:sergroj@mail.ru