Table Extensions
Ratchet expands on the standard table library to give you a few more functions for convenience. All standard Lua functions are available as well and not listed on this page.
copy function
Creates a deep copy of a table to break reference from the original.
Syntax:
table|nil table.copy( table original )merge function
Merges multiple tables into one. Any amount of tables can be specified.
Syntax:
table table.merge( [ table first, ... ] )swap function
Swaps keys with values in a table.
Syntax:
table|nil table.swap( table original )reverse function
Syntax:
table|nil table.reverse( table original )shuffle function
Syntax:
table|nil table.shuffle( table original )keys function
Syntax:
table|nil table.keys( table list )values function
Syntax:
table|nil table.values( table list )unique function
Returns a new table containing each unique value only once (removing any duplicates), preserving the order of first occurrence.
Syntax:
table|nil table.unique( table list )contains function
Syntax:
bool table.contains( table list, mixed value )isEmpty function
Checks whether a table is completely empty.
Syntax:
bool table.isEmpty( table list )count function
Returns the number of keys in a table, effectively counting the number of elements.
This should be used for non-sequential tables, otherwise standard # is more efficient.
Syntax:
int table.count( table list )random function
Returns a random value from the table.
Syntax:
mixed table.random( table list )