We use tolua++ to generate Lua bindings for C++ classes.
Assume I have a C++ class:
class Foo
{
//Some methods in Foo, irrelevant to question.
};
and a tolua .pkg file with the following contents
class Foo
{
};
Consider the following function:
void call_some_lua_function(lua_State* luaState)
{
Foo* myFoo = new Foo();
tolua_pushusertype(luaState, (void*)myFoo, "Foo");
//More code to actually call Lua, irrelevant to question.
}
Now, the actual question:
tolua_pushusertype causes a segfault in Lua if the 3rd parameter does not correspond to a valid fully qualified string of a C++ class that was registered with a call to tolua_cclass. So, if parameter 3 where "Bar", we get a segfault.
What I would like to do is the following:
void call_some_lua_function(lua_State* luaState)
{
//determine if tolua is aware of my type, how to do this?
//Something like:
//if(!tolua_iscpptype_registered("Foo"))
//{
// abort gracefully
//}
Foo* myFoo = new Foo();
tolua_pushusertype(luaState, (void*)myFoo, "Foo");
//More code to actually call Lua, irrelevant to question.
}
Is there a way to do this using tolua?