table
Methods on every table.
Call these with .$
A table's slots and its methods share one namespace, and a slot wins. A table with a key called len, rawget or keys hides the method of that name, and the ordinary call then fails with attempt to call 'string' or whatever the slot happens to hold. Nothing warns, because a table with a key called len is legal.
Writing the call as t.$len() reaches the built-in type method directly and never looks at the slots, so it cannot be broken by the data:
let squad = { len = "a field, not a method" }
squad.len() // throws: attempt to call 'string'
squad.$len() // 1
Plain t.len() is fine for a table whose keys you wrote yourself. For anything parsed from a file, received over a network, or handed in by a caller, prefer .$. The same applies to class and instance members, which share their namespace the same way. See the .$ operator.
Functions
| __merge | pure (table|class).__merge(other: table|instance|class, ...): any | Returns a new table built from this table and every argument, later arguments overriding earlier ones. |
| __update | (table|class).__update(other: table|instance|class, ...): any | Copies every slot from each argument into the table, in place, later arguments overriding earlier ones. |
| clear | clear(): any | Removes every key/value pair from the table, in place. |
| clone | clone(): any | Returns a shallow copy of the table. |
| constructor | constructor(): any | Returns a new, empty table. |
| each | table.each(callback: function): any | Calls callback once for every slot in the table. |
| filter | table.filter(callback: function): any | Returns a new table holding only the slots for which callback returns a truthy result. |
| findindex | pure table.findindex(callback: function): any | Returns the key of the first value for which callback returns a truthy result. |
| findvalue | pure table.findvalue(callback: function, [default], ...): any | Returns the first value for which callback returns a truthy result. |
| getfuncinfos | table.getfuncinfos(): any | If the table has a delegate providing a _call metamethod, returns introspection info about that metamethod's closure; otherwise returns null. |
| hasindex | pure table.hasindex(key): any | Reports whether key is a slot in the table. |
| hasvalue | pure table.hasvalue(value): any | Reports whether value is stored under any key in the table. |
| is_frozen | is_frozen(): any | Reports whether this reference to the table was frozen with freeze(). |
| keys | pure table.keys(): any | Returns an array of every key in the table. |
| len | pure table.len(): any | Returns the number of key/value pairs in the table. |
| map | table.map(callback: function): any | Returns a new table with the same keys, each mapped through callback. |
| rawdelete | table.rawdelete(key): any | Removes the slot at key, without calling a _delslot metamethod. |
| rawget | pure table.rawget(key): any | Returns the value stored under key, without going through a metamethod. |
| rawin | pure table.rawin(key): any | Reports whether key is a slot in the table, without calling a metamethod. |
| rawset | table.rawset(key, value): any | Sets the slot at key to value, creating the slot if it does not exist yet. |
| reduce | table.reduce(callback: function, ...): any | Combines every value in the table into one result by calling callback repeatedly. |
| replace_with | table.replace_with(other: table): any | Replaces the table's entire contents with a copy of other's slots, in place. |
| swap | table.swap(key1, key2): any | Exchanges the values stored at key1 and key2. |
| topairs | table.topairs(): any | Returns an array of [key, value] pairs, one per slot in the table. |
| tostring | tostring(): any | Returns a string that names the type and identity of the table. |
| values | pure table.values(): any | Returns an array of every value in the table. |
| weakref | weakref(): any | Returns a weak reference to the table. |