dcsext.table
Table - extensions to lua tables.
Contents
- Functions
- _t.hasFunc(tbl, func)
- _t.iterators.hasFunc(tbl, iterator, func)
- _t.iterators.sortedPairs(tbl, order)
- _t.contains(tbl, val)
- _t.deepCopy(obj)
- _t.foreachCall(tbl, iterator, func)
- _t.foreachProtectedCall(tbl, iterator, func, logger)
- _t.getKey(tbl, val)
- _t.getKeys(tbl)
- _t.merge(dest, source)
- _t.shallowCopy(obj)
Functions
_t.hasFunc(tbl, func)
Metatables will be used during the test.
Parameters
- tbl
- the table to check
- func
- the function name string to test for existance of
Returns
- boolean, true means the table has an entry that is a function
_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
funcfunction. - 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.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
funcfunction. - 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
funcfunction. - 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