lua_register & C++ member functions
Hi everyone
// Create a class with a member function
Class Stomach
{
public:
int luaDigest(lua_State *luaVM);
};
...
// Define member function
...
// Create a stomach obj in the main somewhere
Stomach aStmch;
// Register member function (or try anyway)
lua_register(g_luaVM, "Digest", aStmch.Digest);
...
When this is compiled I get this error:
Source\Main.cpp(166) : error C2664: 'lua_pushcclosure' : cannot convert parameter 2 from 'int (lua_State *)' to 'lua_CFunction'
None of the functions with this name in scope match the target type
How can I register a member function of a class to lua??
You cannot treat a non-static member-function pointer as a non-member-function pointer, and you certainly cannot make a member-function "closure" in C++, as you are trying to do here. You could make a global or static member function that turns around and calls the appropriate function. Alternatively, you could look into LuaBind, which will do much of this stuff for youl
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement