Getting Luabind error line number with coroutines.

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

Getting Luabind error line number with coroutines.

Alexander Gladysh
Hi, all!

To get stacktrace (and vital file/line info) on Luabind error messages
I'm doing following:

    int OnPcallError(lua_State * L)
      lua_pushliteral(L, "_TRACEBACK");
      lua_rawget(L, LUA_GLOBALSINDEX);
      lua_call(L, 0, 1);
      return 1;


  //  Calling this in my luabind::error exception handler:
  std::string GetLuabindErrorString(const luabind::error & err)
    lua_State * L = err.state();

    const char * pStr = lua_tostring(L, -1);
    if (!pStr)
      return "(No error message on stack)";

    std::string result(pStr);
    lua_pop(L, 1);

    //  Get stack trace.
    pStr = lua_tostring(L, -1);
    if (pStr)
      result += std::string(pStr);
      lua_pop(L, 1);

    return result;

However, this approach does not work for errors raised from coroutines
(with luabind::resume() for example). The OnPcallError() handler does
not get called at all (because, lua_pcall is not called in such
scenario). I know that lua_resume() does not support error callbacks.

However, I need any solution to get error info like file and line (or,
better, whole stacktrace) for Luabind errors -- this problem greatly
complicates writing of scripts by inexperienced coders (like

Thanks in advance,

Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
<a href="">
luabind-user mailing list
[hidden email]