Lua-API++  2015-02-12-3
Lua-API++ library
Table Class Referencefinal

Table object with specialized interface. Similar to Value, it owns a stack slot. More...

Inherits noNew.

Public Member Functions

Life cycle
 Table (const Valref &val)
 Create a copy of referenced value in owned slot. More...
 
 Table (Table &&)
 It is possible to return Table from functions, but actually moving it is not.
 
Tableoperator= (const Table &)=delete
 Tables cannot be assigned to.
 
 Table (Context &context, size_t arrSize=0, size_t recSize=0) noexcept
 Create a new empty table. More...
 
 Table (Temporary src)
 Take ownership of a temporary value. More...
 
Type conversion
 operator Valref & () noexcept
 Reference to owned slot.
 
 operator const Valref & () const noexcept
 Const reference to owned slot.
 
Comparisons (table needs only equality checks).
bool operator== (Valobj rhs) const
 
bool operator!= (Valobj rhs) const
 
Miscellaneous
Temporary len () const noexcept
 Length [Lua 5.2+ only]. More...
 
size_t rawlen () const noexcept
 Raw length [Lua 5.2+ only]. More...
 
size_t len () const noexcept
 Length [Lua 5.1 only].
 
Temporary mt () const noexcept
 Metatable access. More...
 
Iteration
template<typename IterationFunction >
size_t iterate (IterationFunction ifunc) const
 Iterate over all table elements. More...
 
Pre-filled table creation
template<typename... ValueTypes>
Temporary array (Context &context, ValueType...values)
 Create filled array table. More...
 
template<typename... KeyValueTypes>
Temporary records (Context &context, KeyValueTypes...keyValuePairs)
 Create filled table filled with records. More...
 

Related Functions

(Note that these are not member functions.)

Comparisons (table needs only equality checks).
bool operator== (Valobj lhs, const Table &rhs)
 
bool operator!= (Valobj lhs, const Table &rhs)
 

Indexation

RawAccessor raw
 Accessor for raw reads/writes (skip metatable). More...
 
Temporary operator[] (Valobj index) const noexcept
 Indexation works as in normal Valref.
 

Detailed Description

Table object with specialized interface. Similar to Value, it owns a stack slot.

This class is similar to Value, but it offers interface tailored for table manipulation. Many generic operations are absent while new special methods and members are added.

Constructor & Destructor Documentation

Table ( const Valref val)
inline

Create a copy of referenced value in owned slot.

Exceptions
std::runtime_errorif the source is not a table.
Table ( Context context,
size_t  arrSize = 0,
size_t  recSize = 0 
)
explicitnoexcept

Create a new empty table.

Anonymous tables cannot be used as Lua values.

Table ( Temporary  src)

Take ownership of a temporary value.

Exceptions
std::runtime_errorif the source is not a table.

Member Function Documentation

Temporary len ( ) const
noexcept

Length [Lua 5.2+ only].

Same as Valref::len.

size_t rawlen ( ) const
noexcept

Raw length [Lua 5.2+ only].

Same as Valref::rawlen.

Temporary mt ( ) const
noexcept

Metatable access.

Same as Valref::mt()

size_t iterate ( IterationFunction  ifunc) const

Iterate over all table elements.

Template Parameters
IterationFunctionA bool( Valref key, Valref value) function/functor.
Parameters
ifuncFunction that processes key-value pairs. Return value tells wheter to continue(true) or break(false) the iteration.
Note
During iteration any existing Valset will be blocked.
Temporary array ( Context context,
ValueType...  values 
)

Create filled array table.

This functions accepts arbitrary number of Valobj values that fill the table under sequential numeric indices starting with 1.

Note
Without inlining and other optimizations, excessive amount of arguments could lead to stack overflow (native stack, not Lua stack).
Value sets and call results will be expanded.
Temporary records ( Context context,
KeyValueTypes...  keyValuePairs 
)

Create filled table filled with records.

This functions accepts arbitrary even number of Valobj values. Each pair is interpreted as key and value. Repeated keys cause overwrite of corresponding value, no error is generated.

Note
Without inlining and other optimizations, excessive amount of arguments could lead to stack overflow (native stack, not Lua stack).
Value sets cannot be used with this function, and call results will be treated as a single value (no expansion).

Friends And Related Function Documentation

bool operator== ( Valobj  lhs,
const Table rhs 
)
related
bool operator!= ( Valobj  lhs,
const Table rhs 
)
related

Member Data Documentation

RawAccessor raw

Accessor for raw reads/writes (skip metatable).

This member is indexed with any suitable value just like Valref.