I'm called lua_pcall function is a c++ calss object, and the error handler is Lua_CFunction, so no have the class info, How get some infomation from error handler?
// The error handler
static int traceback( lua_State *L)
{
auto msg = CLua::GetCallStack(L);
cout << msg << endl;
return 0;
}
// the class function
bool CLua::RunFunction(const string & strFunctionName , ...)
{
// push error handler
lua_pushcfunction(m_pScriptContext,traceback);
auto nErr = lua_gettop(m_pScriptContext);
PushFunction(strFunctionName);
...
// push params.
...
auto res = lua_pcall(m_pScriptContext, 4, LUA_MULTRET, nErr);
lua_remove( m_pScriptContext, nErr );
if( res != LUA_OK )
{
**// In here I want get msg from the error handler.**
return false;
}
}
When error happened, the lua will call the error handler function "traceback". and then, this function will do something, then return. And in lua_pcall function caller "RunFunction", just have an error code, how get the traceback function info?
This class will have many object, so cannot use the global variable to trans it. have any other way?