Library
Table
Utility functions for manipulating Lua tables.
Shared Functions
Contains
Checks if a value exists in a table.
local isContained = dLib.Table.Contains(tbl, value)| Argument | Type | Description |
|---|---|---|
tbl | table | The table to search within. |
value | any | The value to check for existence in the table. |
| Returned Data | Type | Description |
|---|---|---|
isContained | boolean | True if the value exists in the table, false otherwise. |
Matches
Compares two tables for equality, checking that both tables contain the same key-value pairs.
local matches = dLib.Table.Matches(tableOne, tableTwo)| Argument | Type | Description |
|---|---|---|
tableOne | table | The first table to compare. |
tableTwo | table | The second table to compare. |
| Returned Data | Type | Description |
|---|---|---|
matches | boolean | True if both tables contain the same key-value pairs, false otherwise. |
DeepClone
Creates a deep copy of a table, recursively cloning all nested tables.
local clonedTable = dLib.Table.DeepClone(tbl)| Argument | Type | Description |
|---|---|---|
tbl | table | The table to be deep-cloned. |
| Returned Data | Type | Description |
|---|---|---|
clonedTable | table | A new table that is a deep copy of the input table. |
Merge
Merges two tables, combining their key-value pairs. Duplicate keys can optionally be added together.
local tableOne = dLib.Table.Merge(tableOne, tableTwo)| Argument | Type | Description |
|---|---|---|
tableOne | table | The first table; its key-value pairs will be the base for the merge. |
tableTwo | table | The second table; its key-value pairs will be merged into the first table. |
addDuplicateNumbers? | boolean | If true, numeric values for duplicate keys will be added together instead of overwritten. |
| Returned Data | Type | Description |
|---|---|---|
tableOne | table | The modified first table after merging in the key-value pairs from the second table. |
Shuffle
Randomizes the order of elements in a table.
local shuffledTable = dLib.Table.Shuffle(tbl)| Argument | Type | Description |
|---|---|---|
tbl | table | The table whose elements will be shuffled. |
copy? | boolean | If true, shuffle a copy instead of the original table. |
rnd? | function | Optional custom random function; defaults to math.random. |
| Returned Data | Type | Description |
|---|---|---|
shuffledTable | table | The table with its elements in randomized order. |
Map
Transforms each element in a table using a callback function and returns a new table with the results.
local mappedTable = dLib.Table.Map(tbl, cb)| Argument | Type | Description |
|---|---|---|
tbl | table | The table whose elements will be transformed. |
cb | function | Function to apply to each element; receives value and key, returns new value. |
| Returned Data | Type | Description |
|---|---|---|
mappedTable | table | New table containing the transformed elements. |
Count
Returns the number of elements in a table.
local count = dLib.Table.Count(tbl)| Argument | Type | Description |
|---|---|---|
tbl | table | The table whose elements will be counted. |
| Returned Data | Type | Description |
|---|---|---|
count | number | Total number of elements in the table. |