lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]



Hi All,

Iam trying to get error stacktrace when using lua with SWIG .Pls find the
attached code

class Widget
{
...
};

// Execute lua function funcName

bool execFunc( const std::string & funcName, Widget *UIWidget )
{
int noOfArgs = 0;

// L is a global variable for storing Lua_state
if ( UIWidget )
{
// Pass an object of Widget class as first parameter

swig_module_info *module = SWIG_GetModule( L );
swig_type_info *type = SWIG_TypeQueryModule( module, module, "UIWidget *" );

SWIG_NewPointerObj( L, UIWidget, type, 1 ); // uses the type to push to the
interpreter.
noOfArgs ++;
}

int err_func = 0;
lua_pushliteral( L, "err_func" );
lua_rawget( L, LUA_GLOBALSINDEX );  /* get traceback function */
err_func = lua_gettop ( L );
int err = lua_pcall( L, noOfArgs, 0, err_func );

if( err != 0 )
{
// Get the error from the Lua stack and push it to the log.
if( lua_isstring( L, -1 ) )
{
const char* msg = lua_tostring( L, -1 );
}
}

}


This is always failing in lua_pcall, do we need to do anything more in the
"if" block, if( UIWidget ) { ... }
*msg is always a bad pointer.
If I do not push Widget* as a parameter using SWIG or if I do not use an
error handling function, everything works fine.


Any help is greatly appreciated.
-Gokul

_________________________________________________________________
Movie reviews, previews, news and gossips all here! http://content.msn.co.in/Entertainment/Default