Table
table.len
Shared
Returns the length of a table
Syntax
local length = table.len(input)Parameters
| Type | Name | Description |
|---|---|---|
table | input | Table to be measured |
Returns
| Type | Name | Description |
|---|---|---|
int | length | Length of the table |
Examples
local t = {1, 2, 3, 4, 5}
local len = table.len(t)
engine.print("info", len) --5local packed = table.pack(1, nil, 3, nil, 5)
local len = table.len(packed)
engine.print("info", len) --5local t = {1, 2, nil, 4}
local len = table.len(t)
engine.print("info", len) --4 (may vary, depends on #)local t = {}
local len = table.len(t)
engine.print("info", len) --0local t = {1, 2, 3}
engine.print("info", table.len(t)) --3
engine.print("info", #t) --3local args = table.pack("a", nil, "b", nil, "c")
engine.print("info", #args) --May be incorrect with nil holes
engine.print("info", table.len(args)) --5 (always correct)local t = table.pack(1, nil, 2, nil, 3)
for i = 1, table.len(t) do
engine.print("info", i, t[i])
endlocal t = {}
if table.len(t) == 0 then
engine.print("info", "Table is empty")
endlocal t = {10, 20, 30, key = "value"}
local len = table.len(t)
engine.print("info", len) --3 (only counts array part)