Type Function Library (globals) Return value Elements of given table between iandjRevision Current Public Release (2013.1076) Keywords unpack, global Sample code none See also
Returns the elements from the given table. This function is equivalent to the following:
return list[i], list[i+1], ..., list[j]
The difference is that the above code can be written only for a fixed number of elements. By default, i is 1 and j is the length of the list, as defined by the length operator (#).
unpack( list [, i [, j ]] )
Table. The table whose elements will be unpacked.
Number. The index of the table element at which the function will begin unpacking values. Default: 1.
Number. The index of the table element at which the function will stop unpacking values. Default: length of the given table provided by the length (#) operator.
local t =
{
[1] = "first",
[2] = "second",
[3] = "third",
[4] = "fourth",
[5] = "fifth"
}
local two, three, four = unpack( t, 2, 4 )
print( two, three, four )
-- OUTPUT: second third fourth