Appearance
Table
Inherits: LibTSMModule
Functions
CopyFrom
lua
function Lua.Table.CopyFrom(tbl, srcTbl)Copies all entries into one table from another.
Parameters:
| Name | Type | Description |
|---|---|---|
tbl | table<K, V> | The table to copy entries in to |
srcTbl | table<K, V> | The table to copy entries from |
Count
lua
function Lua.Table.Count(tbl)
-> numberGets the number of entries in the table. This can be used when the count of a non-numerically-indexed table is desired (i.e. #tbl wouldn't work).
Parameters:
| Name | Type | Description |
|---|---|---|
tbl | table | The table to get the number of entries in |
Returns:
| Type | Description |
|---|---|
number |
Equal
lua
function Lua.Table.Equal(tbl1, tbl2)
-> booleanChecks if two tables have the same entries (non-recursively).
Parameters:
| Name | Type | Description |
|---|---|---|
tbl1 | table | The first table to check |
tbl2 | table | The second table to check |
Returns:
| Type | Description |
|---|---|
boolean |
Filter
lua
function Lua.Table.Filter(tbl, func, ...)Uses a function to filter the entries in a table.
Parameters:
| Name | Type | Description |
|---|---|---|
tbl | table | The table to be filtered |
func | fun(key: any, value: any, ...): boolean | The filter function which gets passed key, value, ... and returns true if that entry should be removed from the table |
... | any | Optional arguments to be passed to the filter function |
FilterKeyNotInTable
lua
function Lua.Table.FilterKeyNotInTable(tbl, checkTbl)Filters entries in a table by checking if keys exist as keys in another table.
Parameters:
| Name | Type | Description |
|---|---|---|
tbl | table<K, any> | The table to be filtered |
checkTbl | table<K, any> | The table to check against |
FilterValueNotInTable
lua
function Lua.Table.FilterValueNotInTable(tbl, checkTbl)Filters entries in a table by checking if values exist as keys in another table.
Parameters:
| Name | Type | Description |
|---|---|---|
tbl | table<any, V> | The table to be filtered |
checkTbl | table<V, any> | The table to check against |
GetChangedKeys
lua
function Lua.Table.GetChangedKeys(old, new, result)Gets the keys which were changed between two tables.
Parameters:
| Name | Type | Description |
|---|---|---|
old | table<string, any> | The old table |
new | table<string, any> | The new table |
result | table<string, true> | A result table to store the keys which were changed (with a value of true) |
GetCommonValuesSorted
lua
function Lua.Table.GetCommonValuesSorted(tbls, result)Gets the common values from two or more sorted tables.
Parameters:
| Name | Type | Description |
|---|---|---|
tbls | V[][] | The tables to compare |
result | V[] | The result table |
GetDiffOrdered
lua
function Lua.Table.GetDiffOrdered(old, new, inserted, removed)
-> booleanGets the diff between two lists with order taken into account and returns whether or not we were successful.
Parameters:
| Name | Type | Description |
|---|---|---|
old | table | The old list of items |
new | table | The new list of items |
inserted | number[] | A result table to store the indexes which were added to the new table |
removed | number[] | A result table to store the indexes which were removed from the old table |
Returns:
| Type | Description |
|---|---|
boolean |
GetDistinctKey
lua
function Lua.Table.GetDistinctKey(tbl, value)
-> anyGets the distinct table key by value. This function will assert if the value is not found in the table or if more than one key is found.
Parameters:
| Name | Type | Description |
|---|---|---|
tbl | table | The table to look through |
value | any | The value to get the key of |
Returns:
| Type | Description |
|---|---|
any |
GetKeys
lua
function Lua.Table.GetKeys(tbl, keys)Gets the keys from a table and inserts them into another.
Parameters:
| Name | Type | Description |
|---|---|---|
tbl | table<K, any> | The table to get the keys of |
keys | K[] | The table to insert the keys into |
InsertFill
lua
function Lua.Table.InsertFill(tbl, startIndex, numValues, fillValue)Inserts fill values into the table.
Parameters:
| Name | Type | Description |
|---|---|---|
tbl | table | The table to insert into |
startIndex | number | The index to insert at |
numValues | number | The number of fill values to insert |
fillValue | any | The fill value to insert |
InsertFrom
lua
function Lua.Table.InsertFrom(tbl, srcTbl, srcStartIndex, srcEndIndex)Inserts values at the end of a table from a subrange of another table.
Parameters:
| Name | Type | Description |
|---|---|---|
tbl | table | The table to insert into |
srcTbl | table | The table to insert values from |
srcStartIndex | number | The index of the first value in the source table to insert |
srcEndIndex | number | The index of the last value in the source table to insert |
InsertFromIterator
lua
function Lua.Table.InsertFromIterator(tbl, iterFunc, iterObj, iterIndex)Inserts values from an iterator into the table.
Parameters:
| Name | Type | Description |
|---|---|---|
tbl | T[] | The table to insert into |
iterFunc | IteratorObject<fun(): number, T> | The iterator function |
iterObj | any | The iterator object |
iterIndex | any | The iterator index |
InsertMultiple
lua
function Lua.Table.InsertMultiple(tbl, ...)Inserts multiple values into the table.
Parameters:
| Name | Type | Description |
|---|---|---|
tbl | table | The table to insert into |
... | any | Values to insert |
InsertMultipleAt
lua
function Lua.Table.InsertMultipleAt(tbl, index, ...)Inserts multiple values into the table at a specified index.
Parameters:
| Name | Type | Description |
|---|---|---|
tbl | table | The table to insert into |
index | number | The index to insert at |
... | any | Values to insert |
IsSorted
lua
function Lua.Table.IsSorted(tbl, sortFunc, firstIndex, lastIndex)
-> booleanReturns whether or not the table is currently sorted.
Parameters:
| Name | Type | Description |
|---|---|---|
tbl | table | The table to check |
sortFunc | fun(a: any, b: any): boolean | The helper function to use to determine sort order |
firstIndex | number | The first index to check (defaults to 1) |
lastIndex | number | The last index to check (defaults to #tbl) |
Returns:
| Type | Description |
|---|---|
boolean |
IsSortedWithValueLookup
lua
function Lua.Table.IsSortedWithValueLookup(tbl, valueLookup, firstIndex, lastIndex)
-> booleanChecks whether or not the table is currently sorted with a value lookup table.
Parameters:
| Name | Type | Description |
|---|---|---|
tbl | table | tbl The table to sort |
valueLookup | table<any, string | number> | valueLookup The sort value lookup table |
firstIndex | number | The first index to check (defaults to 1) |
lastIndex | number | The last index to check (defaults to #tbl) |
Returns:
| Type | Description |
|---|---|
boolean |
KeyByValue
lua
function Lua.Table.KeyByValue(tbl, value)
-> anyGets the table key by value.
Parameters:
| Name | Type | Description |
|---|---|---|
tbl | table | The table to look through |
value | any | The value to get the key of |
Returns:
| Type | Description |
|---|---|
any |
KeyIterator
lua
function Lua.Table.KeyIterator(tbl)
-> fun():K, tableCreates an iterator from the keys of a table.
Parameters:
| Name | Type | Description |
|---|---|---|
tbl | table<K, any> | The table to iterate over the keys of |
Returns:
| Type | Description |
|---|---|
fun():K | Iterator with fields: key |
table |
MergeSortedWithValueLookup
lua
function Lua.Table.MergeSortedWithValueLookup(tbl1, tbl2, result, valueLookup)Merges two sorted tables with a value lookup table.
Parameters:
| Name | Type | Description |
|---|---|---|
tbl1 | table | The first table to merge |
tbl2 | table | The second table to merge |
result | table | The result table |
valueLookup | table | The sort value lookup table |
Move
lua
function Lua.Table.Move(tbl, fromIndex, toIndex)Moves a value in the table from one index to another in an efficient way.
Parameters:
| Name | Type | Description |
|---|---|---|
tbl | table | The table |
fromIndex | number | The index of the value to move |
toIndex | number | The index to move the value to |
RemoveByValue
lua
function Lua.Table.RemoveByValue(tbl, value)
-> numberRemoves all occurrences of the value in the table and returns the number removed. Only the numerically-indexed entries are checked.
Parameters:
| Name | Type | Description |
|---|---|---|
tbl | table | The table to remove the value from |
value | any | The value to remove |
Returns:
| Type | Description |
|---|---|
number |
RemoveRange
lua
function Lua.Table.RemoveRange(tbl, startIndex, endIndex)Removes a range of indexes from the table.
Parameters:
| Name | Type | Description |
|---|---|---|
tbl | table | The table |
startIndex | number | The first index to remove |
endIndex | number | The last index to remove |
Reverse
lua
function Lua.Table.Reverse(tbl)Reverses a table in place.
Parameters:
| Name | Type | Description |
|---|---|---|
tbl | table | The table to reverse |
ReverseIPairs
lua
function Lua.Table.ReverseIPairs(tbl)
-> fun():number, V, V[], numberIterates over the table in a similar fasion to ipairs() but in reverse.
Parameters:
| Name | Type | Description |
|---|---|---|
tbl | V[] |
Returns:
| Type | Description |
|---|---|
fun():number, V | Iterator with fields: index, value |
V[] | |
number |
RotateRight
lua
function Lua.Table.RotateRight(tbl, amount, startIndex, endIndex)
-> booleanRotates the values in a table to the right and returns whether or not the table was changed.
Parameters:
| Name | Type | Description |
|---|---|---|
tbl | table | The table to rotate |
amount | number | The number of positions to rotate right by (can be negative to rotate left) |
startIndex | number | Used with endIndex to specify a sub-range of the table to rotate |
endIndex | number | Used with startIndex to specify a sub-range of the table to rotate |
Returns:
| Type | Description |
|---|---|
boolean |
SetReadOnly
lua
function Lua.Table.SetReadOnly(tbl)Sets a table as read-only (modifications aren't checked).
Parameters:
| Name | Type | Description |
|---|---|---|
tbl | table | The table to make read-only |
Sort
lua
function Lua.Table.Sort(tbl, sortFunc)Sorts a table if it's not already sorted.
Parameters:
| Name | Type | Description |
|---|---|---|
tbl | table | The table to sort |
sortFunc | fun(a: any, b: any): boolean | The helper function to use to determine sort order |
SortWithValueLookup
lua
function Lua.Table.SortWithValueLookup(tbl, valueLookup, reverse, secondarySortFunc)Does a table sort with an extra value lookup step.
Parameters:
| Name | Type | Description |
|---|---|---|
tbl | table | The table to sort |
valueLookup | table | The sort value lookup table |
reverse | boolean | Reverse the sort order |
secondarySortFunc | fun(a: any, b: any): boolean | A secondary sort function for when the sort values are equal |
StrideIterator
lua
function Lua.Table.StrideIterator(tbl, numFields)
-> fun():number, ...any, table, numberIterates over a table with a stride. NOTE: This iterator must be run to completion and not be interrupted (i.e. with a break or return).
Parameters:
| Name | Type | Description |
|---|---|---|
tbl | table | The table to iterate over. |
numFields | number | The number of fields to unpack with each iteration |
Returns:
| Type | Description |
|---|---|
fun():number, ...any | Iterator with fields: index, {numFields...} |
table | |
number |
UnpackAndWipe
lua
function Lua.Table.UnpackAndWipe(tbl)
-> ...anyReturns the result of calling unpack() on the table and wipes it.
Parameters:
| Name | Type | Description |
|---|---|---|
tbl | table | The table |
Returns:
| Type | Description |
|---|---|
...any |
WipeAndDeallocate
lua
function Lua.Table.WipeAndDeallocate(tbl)Wipes a table and deallocates the extra memory used by its keys.
Parameters:
| Name | Type | Description |
|---|---|---|
tbl | table |