|
AGXDynamics
2.31.1.0
|
The class encapsulates method calls from C++ to lua. More...
#include <LuaCall.h>
Public Member Functions | |
| LuaCall (lua_State *lua, const std::string &type, void *this_ptr, const std::string &method) | |
| Constructor. More... | |
| LuaCall (lua_State *lua, const std::string &functionName) | |
| LuaCall (lua_State *lua, const agxStream::ClassInformation &classInfo, const void *this_ptr) | |
| ~LuaCall () | |
| bool | call (int num_return_values) |
| Push a pointer to a known usertype. More... | |
| const std::string & | getLastError () const |
| Return message string of last error message (from previous call to call() method). "" if no error occurred. More... | |
| std::string | getStackTrace () const |
| Return the current stack trace. More... | |
| bool | isValid () |
| Returns true if a call to the method can safely be done ( the method exists in lua) More... | |
| void | pushBoolean (bool value) |
| Push a boolean as an argument. More... | |
| void | pushInteger (int value) |
| Push an integer as an argument. More... | |
| void | pushNumber (double value) |
| Push a number as an argument. More... | |
| void | pushString (const std::string &value) |
| Push a string as an argument. More... | |
| bool | pushUsertype (void *value, const char *type) |
| Push a pointer of userdata as an argument. More... | |
| void | pushValue (int lo) |
| Push a value as an argument. More... | |
The class encapsulates method calls from C++ to lua.
The usage of this class enables a call such as:
return_value = this->method(args...);
The constructor takes a pointer to an object, this is the "this" pointer which is of a known lua user type.
The name of the method is given as a string parameter.
By default the constructor will Throw an exception if the function does not exist.
IMPORTANT: Make sure you make a call to LuaCall:call() if isValid() returns true
after the constructor have been called. Otherwise the lua stack would most probably
be corrupted.
Example usage:
MyClass::callLua(MyArgument& arg) {
LuaCall lc(luaVM, this, "MyClass", "luaMethod", false);
if (!lc.valid()) {
cerr << "Invalid call to non existing method";
return;
}
The argument to the method lc.pushUsertype(&arg, "MyArgument"); lc.call(0); //Make the call, return 0 arguments }
The lua code for this setup would then be:
mc= MyClass:new() function mc:luaMethod(arg) print("The call succeeded") end
ma = MyArgument:new() mc:callLua(ma) // Called from luaClass that encapsulates method calls from C++ to lua
| agxLua::LuaCall::LuaCall | ( | lua_State * | lua, |
| const std::string & | type, | ||
| void * | this_ptr, | ||
| const std::string & | method | ||
| ) |
Constructor.
| lua | - A pointer to the VM of lua |
| type | - A string that is the type of the this pointer (must be known by lua as usertype) |
| this_ptr | - A void pointer to this-> |
| method | - A string containing the name of the method to be called |
| agxLua::LuaCall::LuaCall | ( | lua_State * | lua, |
| const std::string & | functionName | ||
| ) |
| agxLua::LuaCall::LuaCall | ( | lua_State * | lua, |
| const agxStream::ClassInformation & | classInfo, | ||
| const void * | this_ptr | ||
| ) |
| agxLua::LuaCall::~LuaCall | ( | ) |
| bool agxLua::LuaCall::call | ( | int | num_return_values | ) |
Push a pointer to a known usertype.
Perform the actual call. If the function call is valid (the method exists in lua) a call will be made with the pushed arguments.
| num_return_values | - Specifies the number of arguments that will be returned by the lua method |
| const std::string& agxLua::LuaCall::getLastError | ( | ) | const |
Return message string of last error message (from previous call to call() method). "" if no error occurred.
| std::string agxLua::LuaCall::getStackTrace | ( | ) | const |
Return the current stack trace.
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
Push a string as an argument.
Definition at line 130 of file LuaCall.h.
References agxLua::pushstring().
|
inline |
Push a pointer of userdata as an argument.
Definition at line 137 of file LuaCall.h.
References agxLua::pushusertype().
|
inline |