Table
The SD.Table
module provides utility functions for working with tables in Lua. This document details each function's purpose, parameters, return values, and usage examples.
Table.Contains
SD.Table.Contains(tbl, value)
SD.Table.Contains(tbl, value)
Purpose: Checks if a specific value exists within a table.
Parameters:
tbl
(table
): The table to search through.value
(any
): The value to search for.
Returns:
(
boolean
): Returnstrue
if the value exists in the table,false
otherwise.
Usage Example:
Table.RemoveValue
SD.Table.RemoveValue(tbl, value)
SD.Table.RemoveValue(tbl, value)
Purpose: Removes an occurrence of a specified value from the table.
Parameters:
tbl
(table
): The table from which the value is to be removed.value
(any
): The value to remove.
Returns: None.
Usage Example:
Table.IndexOf
SD.Table.IndexOf(tbl, object)
SD.Table.IndexOf(tbl, object)
Purpose: Returns the index of a given value in the table, if present.
Parameters:
tbl
(table
): The table to search through.object
(any
): The value whose index is to be found.
Returns:
(
integer
|nil
): The index of the value, ornil
if not found.
Usage Example:
Table.AddUnique
SD.Table.AddUnique(tbl, value)
SD.Table.AddUnique(tbl, value)
Purpose: Adds a value to the table if it is not already present.
Parameters:
tbl
(table
): The table to add the value to.value
(any
): The value to add if it is unique.
Returns: None.
Usage Example:
Table.MergeTables
SD.Table.MergeTables(tbl1, tbl2)
SD.Table.MergeTables(tbl1, tbl2)
Purpose: Merges the contents of the second table into the first table.
Parameters:
tbl1
(table
): The first table to merge into.tbl2
(table
): The second table whose values will be added to the first.
Returns: None.
Usage Example:
Table.Filter
SD.Table.Filter(tbl, predicate)
SD.Table.Filter(tbl, predicate)
Purpose: Filters a table based on a predicate function, producing a new table.
Parameters:
tbl
(table
): The table to be filtered.predicate
(function
): The function to determine if an element should be included. It takes an element and its key as arguments.
Returns:
(
table
): A new table containing only elements that satisfy the predicate.
Usage Example:
Table.Map
SD.Table.Map(tbl, transform)
SD.Table.Map(tbl, transform)
Purpose: Creates a new table by applying a transformation function to each element of the original table.
Parameters:
tbl
(table
): The table to be mapped.transform
(function
): The transformation function applied to each element. It takes an element and its key as arguments.
Returns:
(
table
): A new table containing the results of the transform function applied to each element.
Usage Example:
Last updated