Reputation: 2606
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.
Upvotes: 2
Views: 453
Reputation: 23737
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]
Upvotes: 2