Table
table.unpack
Shared
Unpacks table elements into individual values
Syntax
local ... = table.unpack(input, start_at = 1, end_at = table.len(input))Parameters
| Type | Name | Description |
|---|---|---|
table | input | Table to be unpacked |
int | start_at | Position where unpacking starts |
int | end_at | Position where unpacking ends |
Returns
| Type | Name | Description |
|---|---|---|
... | ... | Unpacked values from the table |
Examples
local t = {10, 20, 30}
local a, b, c = table.unpack(t)
engine.print("info", a, b, c) --10 20 30local coords = {100, 200, 50}
engine.print("info", table.unpack(coords)) --Same as engine.print("info", 100, 200, 50)local t = {1, 2, 3, 4, 5}
local a, b = table.unpack(t, 2, 3)
engine.print("info", a, b) --2 3local t = {"a", "b", "c", "d"}
local x, y, z = table.unpack(t, 2)
engine.print("info", x, y, z) --'b' 'c' 'd'local t = {42}
local value = table.unpack(t)
engine.print("info", value) --42local t = {1, nil, 3}
local a, b, c = table.unpack(t)
engine.print("info", a, b, c) --1 nil 3local a, b = 10, 20
a, b = table.unpack({b, a})
engine.print("info", a, b) --20 10local color = {255, 128, 0}
local r, g, b = table.unpack(color)
setColor(r, g, b)local data = {true, "success", 100}
local status, message, code = table.unpack(data)
engine.print("info", status, message, code) --true "success" 100local t = {1, 2}
local a, b, c, d = table.unpack(t)
engine.print("info", a, b, c, d) --1 2 nil nillocal week = {"Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"}
local first, second, third = table.unpack(week, 1, 3)
engine.print("info", first, second, third) --'Mon' 'Tue' 'Wed'