Skip to content

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:

lua
table|nil table.copy( table original )

merge function ​

Merges multiple tables into one. Any amount of tables can be specified.

Syntax:

lua
table table.merge( [ table first, ... ] )

swap function ​

Swaps keys with values in a table.

Syntax:

lua
table|nil table.swap( table original )

reverse function ​

Syntax:

lua
table|nil table.reverse( table original )

shuffle function ​

Syntax:

lua
table|nil table.shuffle( table original )

keys function ​

Syntax:

lua
table|nil table.keys( table list )

values function ​

Syntax:

lua
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:

lua
table|nil table.unique( table list )

contains function ​

Syntax:

lua
bool table.contains( table list, mixed value )

isEmpty function ​

Checks whether a table is completely empty.

Syntax:

lua
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:

lua
int table.count( table list )

random function ​

Returns a random value from the table.

Syntax:

lua
mixed table.random( table list )