dcsex.table

Table - extensions to lua tables.

Contents

  1. Functions
    1. _t.iterators.hasFunc(tbl, iterator, func)
    2. _t.iterators.sortedPairs(tbl, order)
    3. _t.contains(tbl, val)
    4. _t.deepCopy(obj)
    5. _t.dump(tbl)
    6. _t.foreachCall(tbl, iterator, func)
    7. _t.foreachProtectedCall(tbl, iterator, func, logger)
    8. _t.getKey(tbl, val)
    9. _t.getKeys(tbl)
    10. _t.merge(dest, source)
    11. _t.shallowCopy(obj)

Functions

_t.iterators.hasFunc(tbl, iterator, func)

Parameters

tbl
the table of objects whos keys do not matter and whos values are the objects to be checked if the object implements the optional func function.
iterator
callback to iterate over tbl, used in for loop.
func
the name of the function to check for and execute if exists.

_t.iterators.sortedPairs(tbl, order)

Parameters

tbl
The table to iterate over
order
optional function to sort tbl keys with

Returns

  • an iterator to be used in the generic for loop

_t.contains(tbl, val)

Parameters

tbl
table to search
val
value to look for

Returns

  • True if table contains val, false otherwise

_t.deepCopy(obj)

This is an expensive operation.

Parameters

obj
the object to copy

Returns

  • A deep copy of obj

_t.dump(tbl)

Parameters

tbl
A table

Returns

  • A string representaton of the table

_t.foreachCall(tbl, iterator, func)

Parameters

tbl
the table of objects whos keys do not matter and whos values are the objects to be checked if the object implements the optional func function.
iterator
callback to iterate over tbl, used in for loop.
func
the name of the function to check for and execute if exists.

_t.foreachProtectedCall(tbl, iterator, func, logger)

Parameters

tbl
the table of objects whos keys do not matter and whos values are the objects to be checked if the object implements the optional func function.
iterator
callback to iterate over tbl, used in for loop.
func
the name of the function to check for and execute if exists.
logger
to report errors.

_t.getKey(tbl, val)

If val not found return nil.

Parameters

tbl
the table to search
val
the value to find

Returns

  • The key associated with val in the table or nil

_t.getKeys(tbl)

Parameters

tbl
the table to pull keys from

Returns

  • array of keys from tbl

_t.merge(dest, source)

Note the values in source are not deep copied.

Parameters

dest
the table keys/values from source will be saved to
source
table of key/values to copy

Returns

  • a table of merged keys/values

_t.shallowCopy(obj)

Parameters

obj
the object to clone

Returns

  • a new table that is a copy of obj