No, ... is a tuple, a tuple is as if you returned more than 1 thing
return 10, 15
It’s not a table, you have to make it a table yourself by putting it around {}.
... is generally used for when you expect yourself/the user to pass in multiple arguments, instead of making a lot of parameters you could use ...
Take the sum example again, we don’t know how many arguments we’ll pass in, they could pass in 2 or 20 for example, so ... is needed there instead of named parameters
That’s all I had to say about it, it’s to indicate that the user can input as many arguments as they want without naming them. The usage depends so I can’t comment on that. I would recommend reading the article I’ve listed in my post if you want more info or to do research.
Actually I understood the basics of it. But I’m looking for another example rather than printing. But if you find any examples, kindly please share it.
By that time I’m just going to play around with it!
I did give another usage of it though, the sum function
function sum(...)
local sum = 0
for _, value in ipairs({...}) do
sum += value
end
return sum
end
We first initalize a sum variable, then we turn the ... tuple into a table and loop through it, and we increment sum by the number in that index and then at the end, return the sum of all numbers. So if I did
print(sum(7, 5, 4))
It would print out 16 because the sum of 7, 5 and 4 is 16