pack( ... )
- Creates a table from the given parameters.
- ...
-
- parameters
Returns a new table with all parameters stored sequentially into keys [1], [2], etc.
The table will also contain a member .n which specifies how many arguments were passed to pack()
, including nil arguments. This can be used to detect the difference between an argument that was not passed at all and a nil value that was deliberately passed, since the #
operator stops when it reaches a nil value.
Examples[]
tbl = pack(x, y, dx, dy) -- returns {x, y, dx, dy}
print(#tbl) -- prints "4"
print(tbl.n) -- prints "4"
tbl = pack(x, y) -- returns {x, y}
print(#tbl) -- prints "2"
print(tbl.n) -- prints "2"
tbl = pack(x, y, nil, nil) -- returns {x, y}
print(#tbl) -- prints "2"
print(tbl.n) -- prints "4"