types.Table.len
Method on every
tableReturns the number of key/value pairs in the table.
Return value
A non-negative int: the number of slots currently in the table.
Notes
Takes no arguments. t.len() and t.len(1) differ only in that the second throws wrong number of parameters passed to native closure 'len' (2 passed, 1 required) - the VM checks the count before len ever runs.
Example
let t = {a=1, b=2, c=3}
println("t.len() =", t.len())
t.rawdelete("a")
println("t.len() after rawdelete(\"a\") =", t.len())
let empty = {}
println("empty.len() =", empty.len())
try {
t.len(1) // takes no arguments
} catch (e) {
println("t.len(1) throws:", e)
}Output:
t.len() = 3
t.len() after rawdelete("a") = 2
empty.len() = 0
t.len(1) throws: wrong number of parameters passed to native closure 'len' (2 passed, 1 required)See also
keys | Returns an array of every key in the table. |
values | Returns an array of every value in the table. |
rawin | Reports whether key is a slot in the table, without calling a metamethod. |
| table | class index |