TableUtil
Provides a variety of utility Table operations Taken from Nevermore Framework:
- https://github.com/Quenty/NevermoreEngine/blob/version2/Modules/Shared/Utility/Table.lua
- https://github.com/Quenty/NevermoreEngine
Edited by TheEpicTwin
Functions
append
TableUtil.
append
(
target:
table
,
--
Table to append to
source:
table
--
Table read from
) →
table
parameter
table
Concats target
with source
merge
TableUtil.
merge
(
orig:
table
,
--
original table
new:
table
--
new table
) →
table
Shallow merges two tables without modifying either
mergeLists
TableUtil.
mergeLists
(
orig:
table
,
--
original table
new:
table
--
new table
) →
table
Shallow merges two lists without modifying either
swapKeyValue
TableUtil.
swapKeyValue
(
orig:
table
--
original table
) →
table
Swaps keys with v values, overwriting additional values if duplicated
toList
TableUtil.
toList
(
tab:
table
--
Table to convert to a list
) →
table
Converts a table to a list
count
TableUtil.
count
(
tab:
table
--
Table to count
) →
number
--
count
Counts the number of items in tab
.
Useful since __len
on table in Lua 5.2 returns just the array length.
copy
TableUtil.
copy
(
target:
table
Table
to
copy
) →
table
--
New table
Copies a table, but not deep.
deepCopy
TableUtil.
deepCopy
(
target:
table
--
Table to deep copy
) →
table
--
New table
Deep copies a table including metatables
deepOverwrite
TableUtil.
deepOverwrite
(
target:
table
,
--
Target table
source:
table
--
Table to read from
) →
table
--
target
Overwrites a table's value
getIndex
TableUtil.
getIndex
(
haystack:
table
,
--
table to search in
needle:
any
--
Value to search for
) →
number
|
nil
--
The index of the value, if found. Else nil.
Gets an index by value, returning nil
if no index is found.
stringify
TableUtil.
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
TableUtil.
contains
(
table:
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
TableUtil.
overwrite
(
target:
table
,
--
Table to overwrite
source:
table
--
Source table to read from
) →
table
--
target
Overwrites an existing table
readOnly
TableUtil.
readOnly
(
table:
table
--
Table to error on indexing
) →
table
--
The same table
Sets a metatable on a table such that it errors when indexing a nil value
deepReadOnly
TableUtil.
deepReadOnly
(
table:
table
--
Table to error on indexing
) →
table
--
The same table
Recursively sets the table as ReadOnly