Quirrel4.41.0

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

__mergepure (table|class).__merge(other: table|instance|class, ...): anyReturns a new table built from this table and every argument, later arguments overriding earlier ones.
__update(table|class).__update(other: table|instance|class, ...): anyCopies every slot from each argument into the table, in place, later arguments overriding earlier ones.
clearclear(): anyRemoves every key/value pair from the table, in place.
cloneclone(): anyReturns a shallow copy of the table.
constructorconstructor(): anyReturns a new, empty table.
eachtable.each(callback: function): anyCalls callback once for every slot in the table.
filtertable.filter(callback: function): anyReturns a new table holding only the slots for which callback returns a truthy result.
findindexpure table.findindex(callback: function): anyReturns the key of the first value for which callback returns a truthy result.
findvaluepure table.findvalue(callback: function, [default], ...): anyReturns the first value for which callback returns a truthy result.
getfuncinfostable.getfuncinfos(): anyIf the table has a delegate providing a _call metamethod, returns introspection info about that metamethod's closure; otherwise returns null.
hasindexpure table.hasindex(key): anyReports whether key is a slot in the table.
hasvaluepure table.hasvalue(value): anyReports whether value is stored under any key in the table.
is_frozenis_frozen(): anyReports whether this reference to the table was frozen with freeze().
keyspure table.keys(): anyReturns an array of every key in the table.
lenpure table.len(): anyReturns the number of key/value pairs in the table.
maptable.map(callback: function): anyReturns a new table with the same keys, each mapped through callback.
rawdeletetable.rawdelete(key): anyRemoves the slot at key, without calling a _delslot metamethod.
rawgetpure table.rawget(key): anyReturns the value stored under key, without going through a metamethod.
rawinpure table.rawin(key): anyReports whether key is a slot in the table, without calling a metamethod.
rawsettable.rawset(key, value): anySets the slot at key to value, creating the slot if it does not exist yet.
reducetable.reduce(callback: function, ...): anyCombines every value in the table into one result by calling callback repeatedly.
replace_withtable.replace_with(other: table): anyReplaces the table's entire contents with a copy of other's slots, in place.
swaptable.swap(key1, key2): anyExchanges the values stored at key1 and key2.
topairstable.topairs(): anyReturns an array of [key, value] pairs, one per slot in the table.
tostringtostring(): anyReturns a string that names the type and identity of the table.
valuespure table.values(): anyReturns an array of every value in the table.
weakrefweakref(): anyReturns a weak reference to the table.