Tuple

From OpenEUO
Jump to: navigation, search

Definition

A tuple is an ordered sequence of elements. Functions in lua can return more than one value at a time. E.g.,

 local b = function(...)
   local a = {...}
   local c = select('#',...)
   return c, unpack(a)
 end
 local d,e,f = b('A','B','C')
 print(tostring(d)..' '..e..' '..f)
 --> '2 A B'

the example function b takes a variable number of arguments and returns a variable number of results. When called as shown, the resulting tuple is (2,'A','B','C'). Elements of a tuple not assigned to a variable are simply discarded (so 'C', is dropped in the example case).

See Also