types.Table.clear
Method on every
tableclear(): any
Removes every key/value pair from the table, in place.
let squad = {healer = 1, tank = 1}
squad.clear()
println("squad.len() =", squad.len())Output:
squad.len() = 0Return value
The table itself, now empty.
Errors
Throws Cannot modify immutable object when the table was frozen with freeze().
Notes
Takes no arguments. Existing references to the table see it become empty too, since clear mutates the same object rather than building a new one - unlike constructor(), which returns an unrelated new table.
Example
let t = {a=1, b=2}
let alias = t // same table, not a copy
let r = t.clear()
println("t.len() =", t.len())
println("r == t:", r == t) // clear returns the table itself
println("alias.len() =", alias.len()) // the alias sees the same empty table
let frozen = freeze({a=1})
try {
frozen.clear()
} catch (e) {
println("frozen.clear() throws:", e)
}Output:
t.len() = 0
r == t: true
alias.len() = 0
frozen.clear() throws: Cannot modify immutable objectSee also
rawdelete | Removes the slot at key, without calling a _delslot metamethod. |
replace_with | Replaces the table's entire contents with a copy of other's slots, in place. |
is_frozen | Reports whether this reference to the table was frozen with freeze(). |
| table | class index |