Tuple

From OpenEUO
Revision as of 15:35, 1 November 2010 by Ximan (Talk | contribs) (Definition)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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