Hey! So I know there is a way to allow an infinite number of arguments to a function, and that’s using the (...)
syntax.
I do not know, however, how to do it in any capacity. I’ve never really tried, and I can’t find a good article on it.
Could I get an explanation or a link please?
Thank you!
4 Likes
Operatik
(Operatik)
November 26, 2020, 12:34am
#2
local function hahaha(...)
local a, b, c = ...
print(a, b, c)
end
hahaha(2, 4, 8, 9) -- 2 4 8
Looks like it is a real thing, it works. It is not really as used as much nor mentioned frequently. I should really use it more frequently.
11 Likes
Would you know if there’s possibly a way to combine all of the arguments into a table regardless of how many are given?
metryy
(metryy)
November 26, 2020, 12:41am
#4
You can use the table.pack function and pass the tuple to create a table for indexing specific arguments:
local Args = table.pack(...) -- or {...}
print(Args[1]) -- The first arg of the tuple
6 Likes