Skip to content

3.04 Table functions

Lokasenna edited this page Jun 24, 2018 · 1 revision

GUI.table_copy(source[, base])

Copies the contents of one table to another, including metatables and subtables.

Required

source      A table

Optional

base        Will use this as the primary source for copying and then grab any additional keys 
            from 'source' didn't exist here.

Returns a table.

GUI.table_list(t[, max_depth, cur_depth])

For development/debugging purposes. Returns a table's contents as a string, indented to show nesting, etc.

Required

t           A table

Optional

max_depth   How many levels of nesting to read through.
cur_depth   Will "pad" the indenting by this amount of tabs.

Returns a string.

GUI.table_compare(t_a, t_b)

Recursively compares the contents of two tables, since Lua doesn't do this on its own.

Required

t_a         A table
t_b         Another table

Returns a boolean.

GUI.table_find(t, find[, f])

Looks through a table and returns the key of the first matching value.

Required

t           A table
find        Search term - a string, a number, a boolean

Optional

f           Sorting function. Defaults to ```ipairs```.

If you need to find multiple values in the same table, and each is known to only occur once, it will be much more efficient to copy the table with GUI.table_invert and just check for keys as normal.

Returns a string or number.

GUI.table_invert(t)

Returns a table with the keys and values swapped.

Required

t           A table

Returns a table.

GUI.kpairs(t[, f])

For use in place of pairs or ipairs - iterates through a table in alphabetical/numerical order.

Required

t           A table

Optional

f           An iterator function, as with 'pairs' or 'ipairs'. Specify f = "full" to perform 
            a comparison across types. i.e.
            
                12 > "6 apples" -> true