Not directly.
With three exceptions, all operations throw away all except the first value of a tuple. This includes, for example, ==.
e.g., if you define pair() as
function pair()
return 1, 2
end
function triple()
return 1, 2, 3
end
all of the follow are equivalent:
pair() + 5 is just 1 + 5
x = pair() is just x = 1
pair() == 3 is just 1 == 3
(pair()) is just (1) -- this is definitely an interesting one
a, b = pair(), 5 is just a, b = pair()
list[pair()] is just list[1]
The three cases that actually treat tuples as tuples are assignments, table literals, and function calls. All three, the tuple only survives if it's the final thing in its sequence:
a, b, c, d = 4, triple()
a, b, c, d = triple(), 4
list = {5, triple()}
list = {triple(), 5}
print(5, triple())
print(triple(), 5)
Using tuples
You can write a function to use tuples, of course!
function anyEqual(value, ...)
for i = 1, select("#", ...) do
if select(i, ...) == value then
return true
end
end
for _, element in pairs{...} do
if value == element then
return true
end
end
end
if anyEqual(7, gets()) then
end
Though this really isn't the most readable or reasonable solution to this.
If the values are truly 'packaged together' in some way that it's tempting to write code that looks like this, it probably means they should actually be a single object (values stored together in a table or list or dictionary)