VR-Engage  2.2
Loading...
Searching...
No Matches
makVre::DtLuaFunction Class Reference

Detailed Description

This class provides a C++ interface to Lua functions, allowing them to be called with type-safe parameter passing and return value handling. It supports invoking Lua functions with up to five parameters and retrieving the results with proper type conversion.

#include <luaFunction.h>

Inheritance diagram for makVre::DtLuaFunction:
[legend]

Public Member Functions

 DtLuaFunction ()
 
 DtLuaFunction (lua_State &state, int index)
 
virtual ~DtLuaFunction () override
 
 DtLuaFunction (const DtLuaObject &funcObj)
 
 DtLuaFunction (const DtLuaFunction &funcObj)
 
DtLuaFunctionoperator= (const DtLuaObject &funcObj)
 
DtLuaFunctionoperator= (const DtLuaFunction &func)
 
template<typename RT>
RT call ()
 
template<typename RT, typename P0>
RT call (const P0 &arg1)
 
template<typename RT, typename P0, typename P1>
RT call (const P0 &arg1, const P1 &arg2)
 
template<typename RT, typename P0, typename P1, typename P2>
RT call (const P0 &arg1, const P1 &arg2, const P2 &arg3)
 
template<typename RT, typename P0, typename P1, typename P2, typename P3>
RT call (const P0 &arg1, const P1 &arg2, const P2 &arg3, const P3 &arg4)
 
template<typename RT, typename P0, typename P1, typename P2, typename P3, typename P4>
RT call (const P0 &arg1, const P1 &arg2, const P2 &arg3, const P3 &arg4, const P4 &arg5)
 
- Public Member Functions inherited from makVre::DtLuaObject
 DtLuaObject ()
 
 DtLuaObject (lua_State &state, int index)
 
virtual ~DtLuaObject () override
 
 DtLuaObject (const DtLuaObject &orig)
 
DtLuaObjectoperator= (const DtLuaObject &orig)
 
virtual bool operator== (const DtLuaObject &rhs)
 
template<typename RT>
RT get ()
 
virtual void push () const
 
virtual lua_State * state ()
 
virtual std::string serialize ()
 
virtual bool isValid () const
 
virtual bool hasField (const std::string &name, bool resolveDots=true)
 
virtual bool hasField (int index)
 
virtual DtLuaObject operator[] (std::string name)
 
virtual DtLuaObject operator[] (int index)
 
virtual int tableSize ()
 
std::vector< std::string > keys ()
 
template<typename T>
void setField (const std::string &name, const T &val)
 
template<typename T>
void setField (int index, const T &val)
 
- Public Member Functions inherited from makVre::DtLuaValue
virtual ScriptDataTypeEnum type () const
 
virtual std::string typeName () const
 
 DtLuaValue ()
 
 DtLuaValue (bool v)
 
 DtLuaValue (int v)
 
 DtLuaValue (float v)
 
 DtLuaValue (double v)
 
 DtLuaValue (const std::string &v)
 
 DtLuaValue (const char *v)
 
 DtLuaValue (void *v)
 
virtual ~DtLuaValue ()
 
 DtLuaValue (const DtLuaValue &orig)
 
DtLuaValueoperator= (const DtLuaValue &orig)
 
virtual bool isNil () const
 
virtual bool isBool () const
 
virtual bool isInt () const
 
virtual bool isFloat () const
 
virtual bool isDouble () const
 
virtual bool isString () const
 
virtual bool isPointer () const
 
virtual bool isTable () const
 
virtual bool isFunction () const
 
virtual bool boolValue () const
 
virtual int intValue () const
 
virtual float floatValue () const
 
virtual double doubleValue () const
 
virtual std::string stringValue () const
 
virtual void * pointerValue () const
 

Protected Member Functions

virtual void preFunction ()
 
virtual void postFunction (int argc)
 
- Protected Member Functions inherited from makVre::DtLuaObject
virtual bool getItemOnStack (const std::string &name, bool resolveDots)
 
virtual bool getItemOnStack (int index)
 
virtual void setTable (int index)
 

Protected Attributes

int myErrorIndex
 
- Protected Attributes inherited from makVre::DtLuaObject
DtLuaReferencemyReference
 
lua_State * myState
 
- Protected Attributes inherited from makVre::DtLuaValue
ScriptDataTypeEnum myType
 
union { 
 
   bool   myBool 
 
   int   myInt 
 
   float   myFloat 
 
   double   myDouble 
 
   const char *   myString 
 
   void *   myPtr 
 
};  
 

Additional Inherited Members

- Public Types inherited from makVre::DtLuaValue
enum  ScriptDataTypeEnum {
  SCRIPT_NIL , SCRIPT_BOOL , SCRIPT_INT , SCRIPT_FLOAT ,
  SCRIPT_DOUBLE , SCRIPT_STRING , SCRIPT_POINTER , SCRIPT_FUNCTION ,
  SCRIPT_TABLE
}
 

Constructor & Destructor Documentation

◆ DtLuaFunction() [1/4]

makVre::DtLuaFunction::DtLuaFunction ( )

Default constructor.

Creates an empty, invalid function reference

Referenced by DtLuaFunction(), operator=(), and operator=().

◆ DtLuaFunction() [2/4]

makVre::DtLuaFunction::DtLuaFunction ( lua_State & state,
int index )

Constructor from Lua stack value.

Parameters
stateThe Lua state containing the function
indexIndex of the function on the Lua stack

References makVre::DtLuaObject::state().

◆ ~DtLuaFunction()

virtual makVre::DtLuaFunction::~DtLuaFunction ( )
overridevirtual

Virtual destructor.

◆ DtLuaFunction() [3/4]

makVre::DtLuaFunction::DtLuaFunction ( const DtLuaObject & funcObj)

Construct from a Lua object.

Parameters
funcObjLua object referencing a function

Constructs a function reference from a generic Lua object

References makVre::DtLuaObject::DtLuaObject().

◆ DtLuaFunction() [4/4]

makVre::DtLuaFunction::DtLuaFunction ( const DtLuaFunction & funcObj)

Copy constructor.

Parameters
funcObjSource function to copy from

References DtLuaFunction().

Member Function Documentation

◆ operator=() [1/2]

DtLuaFunction & makVre::DtLuaFunction::operator= ( const DtLuaObject & funcObj)

Assignment operator from Lua object.

Parameters
funcObjLua object referencing a function
Returns
Reference to this function object

References DtLuaFunction(), and makVre::DtLuaObject::DtLuaObject().

◆ operator=() [2/2]

DtLuaFunction & makVre::DtLuaFunction::operator= ( const DtLuaFunction & func)

Assignment operator.

Parameters
funcSource function to assign from
Returns
Reference to this function object

References DtLuaFunction().

◆ call() [1/6]

template<typename RT>
RT makVre::DtLuaFunction::call ( )

Calls the Lua function with no parameters.

Template Parameters
RTReturn type to convert the Lua result to
Returns
The result of the function call converted to type RT
Exceptions
std::stringif the function call fails or type conversion fails

◆ call() [2/6]

template<typename RT, typename P0>
RT makVre::DtLuaFunction::call ( const P0 & arg1)

Calls the Lua function with one parameter.

Template Parameters
RTReturn type to convert the Lua result to
P0Type of the first parameter
Parameters
arg1The first parameter to pass to the function
Returns
The result of the function call converted to type RT
Exceptions
std::stringif the function call fails or type conversion fails

◆ call() [3/6]

template<typename RT, typename P0, typename P1>
RT makVre::DtLuaFunction::call ( const P0 & arg1,
const P1 & arg2 )

Calls the Lua function with two parameters.

Template Parameters
RTReturn type to convert the Lua result to
P0Type of the first parameter
P1Type of the second parameter
Parameters
arg1The first parameter to pass to the function
arg2The second parameter to pass to the function
Returns
The result of the function call converted to type RT
Exceptions
std::stringif the function call fails or type conversion fails

◆ call() [4/6]

template<typename RT, typename P0, typename P1, typename P2>
RT makVre::DtLuaFunction::call ( const P0 & arg1,
const P1 & arg2,
const P2 & arg3 )

Calls the Lua function with three parameters.

Template Parameters
RTReturn type to convert the Lua result to
P0Type of the first parameter
P1Type of the second parameter
P2Type of the third parameter
Parameters
arg1The first parameter to pass to the function
arg2The second parameter to pass to the function
arg3The third parameter to pass to the function
Returns
The result of the function call converted to type RT
Exceptions
std::stringif the function call fails or type conversion fails

◆ call() [5/6]

template<typename RT, typename P0, typename P1, typename P2, typename P3>
RT makVre::DtLuaFunction::call ( const P0 & arg1,
const P1 & arg2,
const P2 & arg3,
const P3 & arg4 )

Calls the Lua function with four parameters.

Template Parameters
RTReturn type to convert the Lua result to
P0Type of the first parameter
P1Type of the second parameter
P2Type of the third parameter
P3Type of the fourth parameter
Parameters
arg1The first parameter to pass to the function
arg2The second parameter to pass to the function
arg3The third parameter to pass to the function
arg4The fourth parameter to pass to the function
Returns
The result of the function call converted to type RT
Exceptions
std::stringif the function call fails or type conversion fails

◆ call() [6/6]

template<typename RT, typename P0, typename P1, typename P2, typename P3, typename P4>
RT makVre::DtLuaFunction::call ( const P0 & arg1,
const P1 & arg2,
const P2 & arg3,
const P3 & arg4,
const P4 & arg5 )

Calls the Lua function with five parameters.

Template Parameters
RTReturn type to convert the Lua result to
P0Type of the first parameter
P1Type of the second parameter
P2Type of the third parameter
P3Type of the fourth parameter
P4Type of the fifth parameter
Parameters
arg1The first parameter to pass to the function
arg2The second parameter to pass to the function
arg3The third parameter to pass to the function
arg4The fourth parameter to pass to the function
arg5The fifth parameter to pass to the function
Returns
The result of the function call converted to type RT
Exceptions
std::stringif the function call fails or type conversion fails

◆ preFunction()

virtual void makVre::DtLuaFunction::preFunction ( )
protectedvirtual

Prepares the stack for a function call.

Sets up error handling and pushes the function onto the stack

◆ postFunction()

virtual void makVre::DtLuaFunction::postFunction ( int argc)
protectedvirtual

Cleans up after a function call.

Parameters
argcNumber of arguments that were passed to the function

Removes the error handler and adjusts the stack as needed

Member Data Documentation

◆ myErrorIndex

int makVre::DtLuaFunction::myErrorIndex
protected

Stack index for the error handler function.


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