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

This is the root namespace of the Library. More...

Namespaces

 STRING
 Defines which type of string classes can be pulled and pushed from the stack with the public API and the DSL.
 

Classes

struct  Lua_function
 Structure which is used to call a Lua function. More...
 
class  Proxy_class
 A template wrapper for class objects of type T used by the script binding. More...
 
struct  Lua_ref
 A typed wrapper for a Lua reference. More...
 
class  Script
 OOLua helper class. More...
 
class  Table
 Wrapper around a table in Lua which allows easy usage. More...
 
struct  in_p
 Input parameter trait. More...
 
struct  out_p
 Output parameter trait. More...
 
struct  in_out_p
 Input and output parameter trait. More...
 
struct  cpp_in_p
 Input parameter trait which will be owned by C++. More...
 
struct  lua_out_p
 Output parameter trait which will be owned by Lua. More...
 
struct  light_p
 Input parameter trait. More...
 
struct  light_return
 Return trait for a light userdata type. More...
 
struct  lua_return
 Return trait for a type which will be owned by Lua. More...
 
struct  maybe_null
 Return trait for a pointer which at runtime maybe NULL. More...
 
struct  shared_return
 Converts a raw pointer return type to the supported shared pointer type. More...
 
struct  cpp_acquire_ptr
 Change of ownership to C++. More...
 
struct  lua_acquire_ptr
 Change of ownership to Lua. More...
 
struct  calling_lua_state
 Special parameter type. More...
 
struct  in_p< char * >
 Specialisation for C style strings. More...
 
struct  Abstract
 The class being mirrored is an abstract class. More...
 
struct  Less_op
 Less than operator is defined for the type. More...
 
struct  Equal_op
 Equal operator is defined for the type. More...
 
struct  Not_equal_op
 Not equal operator is defined for the type. More...
 
struct  Less_equal_op
 Less than or equal operator is defined for the type. More...
 
struct  Div_op
 Division operator is defined for the type. More...
 
struct  Mul_op
 Multiplication operator is defined for the type. More...
 
struct  Sub_op
 Subtraction operator is defined for the type. More...
 
struct  Add_op
 Addition operator is defined for the type. More...
 
struct  No_default_constructor
 There is not a default constructor in the public interface yet there are other constructors. More...
 
struct  No_public_constructors
 There are no constructors in the public interface. More...
 
struct  No_public_destructor
 There is not a destructor in the public interface and OOLua will not attempt to delete an instance of this type. More...
 
struct  Register_class_enums
 The class has enums to register. More...
 
struct  Shared
 Overrides the configuration behaviour when creating proxied types. More...
 
struct  No_shared
 Overrides the configuration behaviour when creating proxied types. More...
 
struct  Exception
 Base class for OOLua exceptions. More...
 
struct  Syntax_error
 Reports LUA_ERRSYNTAX. More...
 
struct  Runtime_error
 Reports LUA_ERRRUN. More...
 
struct  Memory_error
 Reports LUA_ERRMEM. More...
 
struct  File_error
 Reports LUA_ERRFILE. More...
 
struct  Type_error
 Reports that a type pulled from the stack was not the type that was asked for. More...
 

Typedefs

typedef Lua_ref< LUA_TTABLE > Lua_table_ref
 Typedef helper for a LUA_TTABLE registry reference.
 
typedef Lua_ref< LUA_TFUNCTION > Lua_func_ref
 Typedef helper for a LUA_TFUNCTION registry reference.
 

Enumerations

enum  Owner { No_change, Cpp, Lua }
 

Functions

template<typename T >
bool set_global (lua_State *vm, char const *name, T &instance)
 Helper function to set a Lua global variable. More...
 
bool set_global (lua_State *vm, char const *name, lua_CFunction instance)
 None template version. More...
 
void set_global_to_nil (lua_State *vm, char const *name)
 Helper function to set a Lua global variable to nil. More...
 
template<typename T >
bool get_global (lua_State *vm, char const *name, T &instance)
 Helper function to set a Lua global variable. More...
 
bool load_chunk (lua_State *vm, std::string const &chunk)
 Loads a chunk leaving the resulting function on the stack. More...
 
bool run_chunk (lua_State *vm, std::string const &chunk)
 Loads and runs a chunk of code. More...
 
bool load_file (lua_State *vm, std::string const &filename)
 Loads a file leaving the resulting function on the stack. More...
 
bool run_file (lua_State *vm, std::string const &filename)
 Loads and runs the file. More...
 
void reset_error_value (lua_State *vm)
 Reset the error state such that a call to OOLUA::get_last_error will return an empty string. More...
 
std::string get_last_error (lua_State *vm)
 Returns the last stored error. More...
 
bool idxs_equal (lua_State *vm, int idx0, int idx1)
 
bool can_xmove (lua_State *vm0, lua_State *vm1)
 Uses the Lua C API to check if it is valid to move data between the states. More...
 
void setup_user_lua_state (lua_State *vm)
 Sets up a lua_State to work with OOLua. More...
 
template<typename T >
void register_class (lua_State *vm)
 Registers the class type T and it's bases with an instance of lua_State. More...
 
template<typename T , typename K , typename V >
void register_class_static (lua_State *const vm, K const &key, V const &value)
 Registers a key K and value V entry into class T. More...
 
template<typename T , typename T1 >
void table_set_value (lua_State *vm, int table_index, T const &key, T1 const &value)
 The table is at table_index which can be either absolute or pseudo in the stack table is left at the index.
 
template<typename T , typename T1 >
bool table_at (lua_State *vm, int const table_index, T const &key, T1 &value)
 The table is at table_index which can be either absolute or pseudo in the stack table is left at the index.
 
void new_table (lua_State *vm, OOLUA::Table &t)
 Creates a new valid OOLUA::Table. More...
 
OOLUA::Table new_table (lua_State *vm)
 Creates a new valid Table. More...
 
template<typename T >
bool pull (lua_State *const vm, T &value)
 Pulls the top element off the stack and pops it. More...
 
template<typename T >
bool pull (lua_State *const vm, T *&value)
 Pulls the top element off the stack and pops it. More...
 
bool pull (lua_State *const vm, void *&lightud)
 Pulls the top element off the stack and pops it. More...
 
bool pull (lua_State *const vm, bool &value)
 Pulls the top element off the stack and pops it. More...
 
bool pull (lua_State *const vm, double &value)
 Pulls the top element off the stack and pops it. More...
 
bool pull (lua_State *const vm, float &value)
 Pulls the top element off the stack and pops it. More...
 
bool pull (lua_State *const vm, oolua_CFunction &value)
 Pulls the top element off the stack and pops it. More...
 
bool pull (lua_State *const vm, Table &value)
 Pulls the top element off the stack and pops it. More...
 
template<typename T >
bool pull (lua_State *const vm, cpp_acquire_ptr< T > const &value)
 Pulls the top element off the stack and pops it. More...
 
template<typename T >
bool push (lua_State *const vm, T const &value)
 Pushes an instance to top of the Lua stack. More...
 
template<typename T >
bool push (lua_State *const vm, OOLUA::lua_acquire_ptr< T > const &value)
 Pushes an instance to top of the Lua stack. More...
 
template<typename T >
bool push (lua_State *const vm, T *const &value)
 Pushes an instance to top of the Lua stack. More...
 
bool push (lua_State *const vm, void *lightud)
 Pushes an instance to top of the Lua stack. More...
 
bool push (lua_State *const vm, bool const &value)
 Pushes an instance to top of the Lua stack. More...
 
bool push (lua_State *const vm, char *const &value)
 Pushes an instance to top of the Lua stack. More...
 
bool push (lua_State *const vm, char const *const &value)
 Pushes an instance to top of the Lua stack. More...
 
bool push (lua_State *const vm, double const &value)
 Pushes an instance to top of the Lua stack. More...
 
bool push (lua_State *const vm, float const &value)
 Pushes an instance to top of the Lua stack. More...
 
bool push (lua_State *const vm, oolua_CFunction const &value)
 Pushes an instance to top of the Lua stack. More...
 
bool push (lua_State *const vm, Table const &value)
 Pushes an instance to top of the Lua stack. More...
 

Variables

static const char version_str [] = OOLUA_STRINGISE(OOLUA_VERSION_MAJ) "." OOLUA_STRINGISE(OOLUA_VERSION_MIN) "." OOLUA_STRINGISE(OOLUA_VERSION_PATCH)
 OOLua version string.
 
static const int version_number = 2*10000+0*1000+1
 OOLua version int.
 

Detailed Description

This is the root namespace of the Library.

There are sub namespaces contained in OOLUA yet mostly these are not meant for general usage, instead this namespace contains all Public API functions, structures etc.

Enumeration Type Documentation

Enumerator
No_change 

No change of ownership

Cpp 

Change in ownership, C++ will now own the instance

Lua 

Change in ownership, Lua will now own the instance

Function Documentation

bool OOLUA::can_xmove ( lua_State vm0,
lua_State vm1 
)

Uses the Lua C API to check if it is valid to move data between the states.

lua_xmove returns without doing any work if the two pointers are the same and fails when using LUA_USE_APICHECK and the states do not share the same global_State.

It may be fine to move numbers between different unrelated states when Lua was not compiled with LUA_USE_APICHECK but this function would still return false for that scenario.

Parameters
[in]vm0
[in]vm1
Returns
true if vm0 and vm1 are different yet none NULL related states, else false
template<typename T >
bool OOLUA::get_global ( lua_State vm,
char const *  name,
T &  instance 
)

Helper function to set a Lua global variable.

Template Parameters
TType for instance
Parameters
[in]vmlua_State
[in]nameGlobal name to query
[out]instanceAny variable which is valid to pull from the stack
Returns
Boolean indicating if the operation was successful
See Also
Error Reporting
bool OOLUA::idxs_equal ( lua_State vm,
int  idx0,
int  idx1 
)

Compares two valid indices on the stack of vm.

Compares the two indicies which will take into consideration metamethods when present for the types.

Parameters
[in]vmThe lua_State in which to preform the operation
[in]idx0Valid stack index
[in]idx1Valid stack index
Returns
bool Result of the comparison
bool OOLUA::load_chunk ( lua_State vm,
std::string const &  chunk 
)

Loads a chunk leaving the resulting function on the stack.

Parameters
[in]vmLua virtual machine. Taken from Lua manual : An opaque structure that points to a thread and indirectly (through the thread) to the whole state of a Lua interpreter. The Lua library is fully reentrant: it has no global variables. All information about a state is accessible through this structure.
[in]chunk
bool OOLUA::load_file ( lua_State vm,
std::string const &  filename 
)

Loads a file leaving the resulting function on the stack.

Parameters
[in]vmLua virtual machine. Taken from Lua manual : An opaque structure that points to a thread and indirectly (through the thread) to the whole state of a Lua interpreter. The Lua library is fully reentrant: it has no global variables. All information about a state is accessible through this structure.
[in]filename
void OOLUA::new_table ( lua_State vm,
OOLUA::Table t 
)

Creates a new valid OOLUA::Table.

Parameters
[in]vmThe lua_State in which to create the table.
[in,out]tTable which will hold the newly created valid table.
Postcondition
stack is the same on exit as entry and t will be an instance on which valid returns true.
OOLUA::Table OOLUA::new_table ( lua_State vm)

Creates a new valid Table.

Postcondition
stack is the same on exit as entry
Parameters
[in]vmThe lua_State in which to create the table
Returns
A newly constructed Table on which valid will return true.
bool OOLUA::pull ( lua_State *const  vm,
void *&  lightud 
)

Pulls the top element off the stack and pops it.

In stack terms this is a top followed by pop.

Returns
If OOLUA_STORE_LAST_ERROR is set to one then the the return value will indicate success or failure, if OOLUA_USE_EXCEPTIONS is set to one then failure will always be reported by throwing an exception.
See Also
Error Reporting
Exception classes
bool OOLUA::pull ( lua_State *const  vm,
bool &  value 
)

Pulls the top element off the stack and pops it.

In stack terms this is a top followed by pop.

Returns
If OOLUA_STORE_LAST_ERROR is set to one then the the return value will indicate success or failure, if OOLUA_USE_EXCEPTIONS is set to one then failure will always be reported by throwing an exception.
See Also
Error Reporting
Exception classes
bool OOLUA::pull ( lua_State *const  vm,
double &  value 
)

Pulls the top element off the stack and pops it.

In stack terms this is a top followed by pop.

Returns
If OOLUA_STORE_LAST_ERROR is set to one then the the return value will indicate success or failure, if OOLUA_USE_EXCEPTIONS is set to one then failure will always be reported by throwing an exception.
See Also
Error Reporting
Exception classes
bool OOLUA::pull ( lua_State *const  vm,
float &  value 
)

Pulls the top element off the stack and pops it.

In stack terms this is a top followed by pop.

Returns
If OOLUA_STORE_LAST_ERROR is set to one then the the return value will indicate success or failure, if OOLUA_USE_EXCEPTIONS is set to one then failure will always be reported by throwing an exception.
See Also
Error Reporting
Exception classes
bool OOLUA::pull ( lua_State *const  vm,
oolua_CFunction &  value 
)

Pulls the top element off the stack and pops it.

In stack terms this is a top followed by pop.

Returns
If OOLUA_STORE_LAST_ERROR is set to one then the the return value will indicate success or failure, if OOLUA_USE_EXCEPTIONS is set to one then failure will always be reported by throwing an exception.
See Also
Error Reporting
Exception classes
bool OOLUA::pull ( lua_State *const  vm,
Table &  value 
)

Pulls the top element off the stack and pops it.

In stack terms this is a top followed by pop.

Returns
If OOLUA_STORE_LAST_ERROR is set to one then the the return value will indicate success or failure, if OOLUA_USE_EXCEPTIONS is set to one then failure will always be reported by throwing an exception.
See Also
Error Reporting
Exception classes
template<typename T >
bool OOLUA::pull ( lua_State *const  vm,
cpp_acquire_ptr< T > const &  value 
)

Pulls the top element off the stack and pops it.

In stack terms this is a top followed by pop.

Returns
If OOLUA_STORE_LAST_ERROR is set to one then the the return value will indicate success or failure, if OOLUA_USE_EXCEPTIONS is set to one then failure will always be reported by throwing an exception.
See Also
Error Reporting
Exception classes
template<typename T >
bool OOLUA::pull ( lua_State *const  vm,
T &  value 
)
inline

Pulls the top element off the stack and pops it.

In stack terms this is a top followed by pop.

Returns
If OOLUA_STORE_LAST_ERROR is set to one then the the return value will indicate success or failure, if OOLUA_USE_EXCEPTIONS is set to one then failure will always be reported by throwing an exception.
See Also
Error Reporting
Exception classes
template<typename T >
bool OOLUA::pull ( lua_State *const  vm,
T *&  value 
)
inline

Pulls the top element off the stack and pops it.

In stack terms this is a top followed by pop.

Returns
If OOLUA_STORE_LAST_ERROR is set to one then the the return value will indicate success or failure, if OOLUA_USE_EXCEPTIONS is set to one then failure will always be reported by throwing an exception.
See Also
Error Reporting
Exception classes
bool OOLUA::push ( lua_State *const  vm,
void *  lightud 
)

Pushes an instance to top of the Lua stack.

Returns
If OOLUA_STORE_LAST_ERROR is set to one then the the return value will indicate success or failure, if OOLUA_USE_EXCEPTIONS is set to one then failure will always be reported by the throwing of an exception.
Note
Although all push methods return a boolean, most simply return true. The only versions which can return false are functions which operate on full userdata and values which are associated with a Lua universe.
See Also
OOLUA::can_xmove
Error Reporting
Exception classes
bool OOLUA::push ( lua_State *const  vm,
bool const &  value 
)

Pushes an instance to top of the Lua stack.

Returns
If OOLUA_STORE_LAST_ERROR is set to one then the the return value will indicate success or failure, if OOLUA_USE_EXCEPTIONS is set to one then failure will always be reported by the throwing of an exception.
Note
Although all push methods return a boolean, most simply return true. The only versions which can return false are functions which operate on full userdata and values which are associated with a Lua universe.
See Also
OOLUA::can_xmove
Error Reporting
Exception classes
bool OOLUA::push ( lua_State *const  vm,
char *const &  value 
)

Pushes an instance to top of the Lua stack.

Returns
If OOLUA_STORE_LAST_ERROR is set to one then the the return value will indicate success or failure, if OOLUA_USE_EXCEPTIONS is set to one then failure will always be reported by the throwing of an exception.
Note
Although all push methods return a boolean, most simply return true. The only versions which can return false are functions which operate on full userdata and values which are associated with a Lua universe.
See Also
OOLUA::can_xmove
Error Reporting
Exception classes
bool OOLUA::push ( lua_State *const  vm,
char const *const &  value 
)

Pushes an instance to top of the Lua stack.

Returns
If OOLUA_STORE_LAST_ERROR is set to one then the the return value will indicate success or failure, if OOLUA_USE_EXCEPTIONS is set to one then failure will always be reported by the throwing of an exception.
Note
Although all push methods return a boolean, most simply return true. The only versions which can return false are functions which operate on full userdata and values which are associated with a Lua universe.
See Also
OOLUA::can_xmove
Error Reporting
Exception classes
bool OOLUA::push ( lua_State *const  vm,
double const &  value 
)

Pushes an instance to top of the Lua stack.

Returns
If OOLUA_STORE_LAST_ERROR is set to one then the the return value will indicate success or failure, if OOLUA_USE_EXCEPTIONS is set to one then failure will always be reported by the throwing of an exception.
Note
Although all push methods return a boolean, most simply return true. The only versions which can return false are functions which operate on full userdata and values which are associated with a Lua universe.
See Also
OOLUA::can_xmove
Error Reporting
Exception classes
bool OOLUA::push ( lua_State *const  vm,
float const &  value 
)

Pushes an instance to top of the Lua stack.

Returns
If OOLUA_STORE_LAST_ERROR is set to one then the the return value will indicate success or failure, if OOLUA_USE_EXCEPTIONS is set to one then failure will always be reported by the throwing of an exception.
Note
Although all push methods return a boolean, most simply return true. The only versions which can return false are functions which operate on full userdata and values which are associated with a Lua universe.
See Also
OOLUA::can_xmove
Error Reporting
Exception classes
bool OOLUA::push ( lua_State *const  vm,
oolua_CFunction const &  value 
)

Pushes an instance to top of the Lua stack.

Returns
If OOLUA_STORE_LAST_ERROR is set to one then the the return value will indicate success or failure, if OOLUA_USE_EXCEPTIONS is set to one then failure will always be reported by the throwing of an exception.
Note
Although all push methods return a boolean, most simply return true. The only versions which can return false are functions which operate on full userdata and values which are associated with a Lua universe.
See Also
OOLUA::can_xmove
Error Reporting
Exception classes
bool OOLUA::push ( lua_State *const  vm,
Table const &  value 
)

Pushes an instance to top of the Lua stack.

Returns
If OOLUA_STORE_LAST_ERROR is set to one then the the return value will indicate success or failure, if OOLUA_USE_EXCEPTIONS is set to one then failure will always be reported by the throwing of an exception.
Note
Although all push methods return a boolean, most simply return true. The only versions which can return false are functions which operate on full userdata and values which are associated with a Lua universe.
See Also
OOLUA::can_xmove
Error Reporting
Exception classes
template<typename T >
bool OOLUA::push ( lua_State *const  vm,
T const &  value 
)
inline

Pushes an instance to top of the Lua stack.

Returns
If OOLUA_STORE_LAST_ERROR is set to one then the the return value will indicate success or failure, if OOLUA_USE_EXCEPTIONS is set to one then failure will always be reported by the throwing of an exception.
Note
Although all push methods return a boolean, most simply return true. The only versions which can return false are functions which operate on full userdata and values which are associated with a Lua universe.
See Also
OOLUA::can_xmove
Error Reporting
Exception classes
template<typename T >
bool OOLUA::push ( lua_State *const  vm,
OOLUA::lua_acquire_ptr< T > const &  value 
)
inline

Pushes an instance to top of the Lua stack.

Returns
If OOLUA_STORE_LAST_ERROR is set to one then the the return value will indicate success or failure, if OOLUA_USE_EXCEPTIONS is set to one then failure will always be reported by the throwing of an exception.
Note
Although all push methods return a boolean, most simply return true. The only versions which can return false are functions which operate on full userdata and values which are associated with a Lua universe.
See Also
OOLUA::can_xmove
Error Reporting
Exception classes
template<typename T >
bool OOLUA::push ( lua_State *const  vm,
T *const &  value 
)
inline

Pushes an instance to top of the Lua stack.

Returns
If OOLUA_STORE_LAST_ERROR is set to one then the the return value will indicate success or failure, if OOLUA_USE_EXCEPTIONS is set to one then failure will always be reported by the throwing of an exception.
Note
Although all push methods return a boolean, most simply return true. The only versions which can return false are functions which operate on full userdata and values which are associated with a Lua universe.
See Also
OOLUA::can_xmove
Error Reporting
Exception classes
template<typename T >
void OOLUA::register_class ( lua_State vm)
inline

Registers the class type T and it's bases with an instance of lua_State.

Template Parameters
TClass type to register with OOLua

Registers a class type T for which there is a Proxy_class and also registers it's bases, if it has any. The function preforms a check to see if the type has already been registered with the instance and is safe to be called multiple times with a Lua universe.

Parameters
[in]vmUniverse to register the class with.
template<typename T , typename K , typename V >
void OOLUA::register_class_static ( lua_State *const  vm,
K const &  key,
V const &  value 
)
inline

Registers a key K and value V entry into class T.

Template Parameters
TClass type to register the static for
KKey
VValue
Parameters
[in]vmlua_State
[in]keyKey to register in type T,
[in]valueThe data to associate with key in the class type T.
bool OOLUA::run_chunk ( lua_State vm,
std::string const &  chunk 
)

Loads and runs a chunk of code.

Parameters
[in]vmLua virtual machine. Taken from Lua manual : An opaque structure that points to a thread and indirectly (through the thread) to the whole state of a Lua interpreter. The Lua library is fully reentrant: it has no global variables. All information about a state is accessible through this structure.
[in]chunk
bool OOLUA::run_file ( lua_State vm,
std::string const &  filename 
)

Loads and runs the file.

Parameters
[in]vmLua virtual machine. Taken from Lua manual : An opaque structure that points to a thread and indirectly (through the thread) to the whole state of a Lua interpreter. The Lua library is fully reentrant: it has no global variables. All information about a state is accessible through this structure.
[in]filename
template<typename T >
bool OOLUA::set_global ( lua_State vm,
char const *  name,
T &  instance 
)

Helper function to set a Lua global variable.

Template Parameters
TType for instance
Parameters
[in]vmlua_State
[in]nameGlobal name to set
[in]instanceAny variable which is valid to push to the stack
Returns
Boolean indicating if the operation was successful
See Also
Error Reporting
bool OOLUA::set_global ( lua_State vm,
char const *  name,
lua_CFunction  instance 
)

None template version.

Enables setting a global with a value of lua_CFunction without requiring you make a reference to the function.

Parameters
[in]vmThe lua_State to work on
[in]nameString which is used for the global name
[in]instanceThe lua_CFuntion which will be set at the global value for name
void OOLUA::set_global_to_nil ( lua_State vm,
char const *  name 
)

Helper function to set a Lua global variable to nil.

Parameters
[in]vmlua_State
[in]nameGlobal name to set
void OOLUA::setup_user_lua_state ( lua_State vm)

Sets up a lua_State to work with OOLua.

If you want to use OOLua with a lua_State you already have active or supplied by some third party, then calling this function adds the necessary tables and globals for it to work with OOLua.

Parameters
[in]vmlua_State to be initialise by OOLua