Table
Provide a variety of utility table operations
Functions
append
Table.append(target: table,--
Table to append to
source: table--
Table read from
) → table--
parameter table
Concats target with source in-place, modifying the target
merge
Table.merge(orig: table,--
Original table
new: table--
Result
) → tableShallow merges two tables without modifying either.
reverse
Table.reverse(orig: table--
Original table
) → tableReverses the list and returns the reversed copy
values
Table.values(source: table--
Table source to extract values from
) → table--
A list with all the values the table has
Returns a list of all of the values that a table has.
keys
Table.keys(source: table--
Table source to extract keys from
) → table--
A list with all the keys the table has
Returns a list of all of the keys that a table has. (In order of pairs)
mergeLists
Table.mergeLists(orig: table,--
Original table
new: table--
Result
) → tableShallow merges two lists without modifying either.
swapKeyValue
Table.swapKeyValue(orig: table--
Original table
) → tableSwaps keys with values, overwriting additional values if duplicated.
toList
Table.toList(_table: table--
Table to convert to a list
) → tableConverts a table to a list.
count
Table.count(_table: table--
Table to count
) → number--
count
Counts the number of items in _table.
Useful since __len on table in Lua 5.2 returns just the array length.
Table.copy
Table.Table.copy(target: table--
Table to copy
) → table--
Result
Shallow copies a table from target into a new table
deepCopy
Table.deepCopy(target: table,--
Table to deep copy
_deepCopyContext: table?--
Context to deepCopy the value in
) → table--
Result
Deep copies a table including metatables
deepOverwrite
Table.deepOverwrite(target: table,--
Target table
source: table--
Table to read from
) → table--
target
Overwrites a table's value
getIndex
Table.getIndex(haystack: table,--
To search in
needle: Valuetosearchfor) → (Theindexofthevalue,iffound,nil--
if not found
)Gets an index by value, returning nil if no index is found.
stringify
Table.stringify(_table: table,--
Table to stringify
indent: number?,--
Indent level
output: string?--
Output string, used recursively
) → string--
The table in string form
Recursively prints the table. Does not handle recursive tables.
contains
Table.contains(_table: table,--
To search in for value
value: any--
Value to search for
) → boolean--
true if within, false otherwise
Returns whether value is within table
overwrite
Table.overwrite(target: table,--
Table to overwite
source: table--
Source table to read from
) → table--
target
Overwrites an existing table with the source values.
deepEquivalent
Table.deepEquivalent(target: table,--
Table to check
source: table--
Other table to check
) → booleanDeep equivalent comparison of a table assuming keys are indexable in the same way.
take
Table.take(source: table,--
Source table to retrieve values from
count: number--
Number of entries to take
) → table--
List with the entries retrieved
Takes count entries from the table. If the table does not have
that many entries, will return up to the number the table has to
provide.
readonly
Table.readonly(target: table--
Table to error on indexing
) → table--
The same table, with the metatable set to readonly
Sets a metatable on a table such that it errors when indexing a nil value
errorOnNilIndex
Table.errorOnNilIndex(target: table--
Table to error on indexing
) → table--
The same table, with the target set to error on nil
Sets a metatable on a table such that it errors when indexing a nil value
deepReadonly
Table.deepReadonly(target: table--
Table to error on indexing
) → table--
The same table
Recursively sets the table as ReadOnly