2

For example, I have a function:

myFunction = function(a1,a2,a3)
end;

And I want to save all the arguments given myFunction inside it by a code which will be correct after changing number of myFunction arguments and their names. It seems to me that it can be done by a for cycle, but I don't know how to call arguments and #arguments in it.

1 Answer 1

2
local saved_arguments

myFunction = function(...)
  -- save the arguments
  saved_arguments = {...}
  local a1, a2, a3 = ...
  -- main code of function
end;

-- Use saved arguments
local last_a1, last_a2, last_a3 = unpack(saved_arguments)
-- do something with last_a1, last_a2, last_a3
-- or use it directly: saved_arguments[1], saved_arguments[2], saved_arguments[3]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.