OOLua  2.0.1
C++ and Lua binding
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
OOLUA::Table Class Reference

Wrapper around a table in Lua which allows easy usage. More...

#include <oolua_table.h>

Public Member Functions

bool valid () const
 Returns a boolean which is the result of checking the state of the internal Lua_func_ref.
 
void traverse (traverse_do_function do_)
 Traverses the table using oolua_pairs. More...
 
lua_Statestate () const
 Provides access to the associated lua_State.
 
 Table ()
 Default creates an object on which a call to valid returns false.
 
 Table (Lua_table_ref const &ref)
 Initialises the reference to be an instance of the same registry reference or an invalid table if ref.valid() == false.
 
 Table (lua_State *const vm, std::string const &name)
 Sets the lua_State and calls Lua_table::set_table.
 
 Table (Table const &rhs)
 Default creates an object on which a call to valid returns false.
 
Tableoperator= (Table const &rhs)
 Assigns a copy of rhs's internal state to this instance. More...
 
void bind_script (lua_State *const vm)
 Associates the instance with the lua_State vm. More...
 
void set_table (std::string const &name)
 Order of trying to initialise : More...
 
void set_ref (lua_State *const vm, int const &ref)
 Initailises the internal Lua_func_ref to the id ref.
 
void swap (Table &rhs)
 Swaps the internal Lua_func_ref and rhs.m_table_ref.
 
template<typename T , typename T1 >
void try_at (T const &key, T1 &value)
 Function which throws on an error. More...
 
template<typename T , typename T1 >
bool safe_at (T const &key, T1 &value)
 A safe version of at, which will always return a boolean indicating the success of the function call. More...
 
template<typename T , typename T1 >
T1 & at (T const &key, T1 &value)
 
template<typename T , typename T1 >
void set (T const &key, T1 const &value)
 Inserts the key value pair into the table if key is not present else it updates the table's key entry.
 
template<typename T >
void remove (T const &key)
 Removes the key from the table by setting it's value to nil.
 

Detailed Description

Wrapper around a table in Lua which allows easy usage.

Table provides a simple typed C++ interface for the Lua unordered and ordered associative container of the same name. Operations which use the Lua stack ensure that the stack is the same on exit as it was on entry, OOLua tries to force a clean stack(OOLua and the Lua stack).

Any value can be retrieved or set from the table via the use of the template member functions set, at or safe_at. If the value asked for is not the correct type located in the position an error can be reported, the type of which depends on Error Reporting and the function which was called. See individual member function documentation for details.

Note
The member function try_at is only defined when exceptions are enabled for the library.

Member Function Documentation

template<typename T , typename T1 >
T1 & Table::at ( T const &  key,
T1 &  value 
)
inline
Template Parameters
TKey type
T1Value type
Parameters
[in]key
[out]valuezreturn The same instance as value
Note
No error checking.
It is undefined to call this function when:
  • table or the key are invalid
  • table does not contain the key
  • value is not the correct type
See Also
Lua_table::safe_at
Lua_table::try_at
void OOLUA::Table::bind_script ( lua_State *const  vm)

Associates the instance with the lua_State vm.

Associates the instance with the lua_State vm. If the table already has a lua_State bound to it

  • If the Current bound instance is not equal to vm and the table has a valid reference, it releases the currently set reference and sets vm as the bound instance.
Table& OOLUA::Table::operator= ( Table const &  rhs)

Assigns a copy of rhs's internal state to this instance.

If this table is valid then the operator will release the registry reference before assigning a copy of rhs to this instance.

Parameters
[in]rhsTable from which to copy the table reference
Returns
This instance.
See Also
OOLUA::Lua_ref assignment operator
template<typename T , typename T1 >
bool Table::safe_at ( T const &  key,
T1 &  value 
)
inline

A safe version of at, which will always return a boolean indicating the success of the function call.

This function will not throw an exception when exceptions are enabled for the library.

Template Parameters
TKey type
T1Value type
Parameters
[in]key
[out]value
void OOLUA::Table::set_table ( std::string const &  name)

Order of trying to initialise :

  • name.empty() == true: Creates an invalid object.
  • name found as a table in Lua global: Swaps the internal Lua_func_ref with an instance initialised to an id obtained from the Lua registry.
  • name found as a table in Lua registry: Swaps the internal Lua_func_ref with an instance initialised to an id obtained from the Lua registry.
  • else Swaps the internal Lua_func_ref with an uninitialised instance.
void OOLUA::Table::traverse ( traverse_do_function  do_)

Traverses the table using oolua_pairs.

See Also
oolua_pairs' details for the correct procedure to follow.
template<typename T , typename T1 >
void OOLUA::Table::try_at ( T const &  key,
T1 &  value 
)

Function which throws on an error.

Note
This function is only defined when exceptions are enable for the library
Template Parameters
TKey type
T1Value type
Parameters
[in]key
[out]value

The documentation for this class was generated from the following file: