Luwra
Minimal-overhead Lua wrapper for C++
Public Member Functions | Public Attributes | List of all members
luwra::Table Struct Reference

Allows you to inspect and modify Lua tables. More...

Inherited by luwra::StateWrapper.

Public Member Functions

template<typename Key >
const internal::TableAccessorPath< const Reference &, Key > access (Key &&key) const
 Identical to operator[]. More...
 
template<typename Type , typename Key >
Type get (Key &&key) const
 Retrieve the value of a field. More...
 
template<typename Key >
bool has (Key &&key) const
 Check if the value associated with a key is not nil. More...
 
template<typename Key >
const internal::TableAccessorPath< const Reference &, Key > operator[] (Key &&key) const
 Create an accessor to a field of the table. More...
 
template<typename Type , typename Key >
void set (Key &&key, Type &&value) const
 Update a field. More...
 
 Table (const Reference &ref)
 Create from reference. More...
 
 Table (State *state, int index)
 Create from table on the stack. More...
 
 Table (State *state)
 Create a new table. More...
 
 Table (State *state, const MemberMap &fields)
 Create a new table with the given fields. More...
 
void update (const MemberMap &fields) const
 Update the table using the given map of members. More...
 

Public Attributes

Reference ref
 

Detailed Description

Allows you to inspect and modify Lua tables.

Constructor & Destructor Documentation

§ Table() [1/4]

luwra::Table::Table ( const Reference ref)
inline

Create from reference.

§ Table() [2/4]

luwra::Table::Table ( State state,
int  index 
)
inline

Create from table on the stack.

§ Table() [3/4]

luwra::Table::Table ( State state)
inline

Create a new table.

§ Table() [4/4]

luwra::Table::Table ( State state,
const MemberMap fields 
)
inline

Create a new table with the given fields.

Member Function Documentation

§ access()

template<typename Key >
const internal::TableAccessorPath<const Reference&, Key> luwra::Table::access ( Key &&  key) const
inline

Identical to operator[].

§ get()

template<typename Type , typename Key >
Type luwra::Table::get ( Key &&  key) const
inline

Retrieve the value of a field.

§ has()

template<typename Key >
bool luwra::Table::has ( Key &&  key) const
inline

Check if the value associated with a key is not nil.

§ operator[]()

template<typename Key >
const internal::TableAccessorPath<const Reference&, Key> luwra::Table::operator[] ( Key &&  key) const
inline

Create an accessor to a field of the table.

Example:

// Retrieve the value of a field.
int value = table["fieldName"];
// Update the value of a field.
table["fieldName"] = 13.37;
// Accessor nesting is also possible, assuming the field 'fieldName' is a table aswell.
table["fieldName"]["nestedFieldName"] = 1337;
int value = table["fieldName"]["nestedFieldName"];

§ set()

template<typename Type , typename Key >
void luwra::Table::set ( Key &&  key,
Type &&  value 
) const
inline

Update a field.

§ update()

void luwra::Table::update ( const MemberMap fields) const
inline

Update the table using the given map of members.

Member Data Documentation

§ ref

Reference luwra::Table::ref