lua-users home
lua-l archive

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

Hi Abhjit

I don't use luabind, but my interfaces to my c++ code tend to look like this

luaFunction (lua_State *L)
         int luaParamCount = lua_gettop(L)  ;
         if  (luaParamCount  >= 1 && luaParams <= 2) 
              int param1 = lua_tointeger (L, 1) ; // always
              int param2 = luaParamCount  > 1 ? lua_tointeger (L, 2) : 0 ; // optional with default

              CPPObject->PublicFunction  (param1, param2) ;
             throw Exception ("Wrong no of parameters") ;
    catch (Exception& e)
        luaL_error (L, (string ("luaFunction:") + e.Message).c_str ()) ;

    return 0 ;

Any error in my C++ functions results in a 'throw Exception ()' - which then reports neatly as a Lua error.

HTH. Regards

From: Abhijit Nandy <>
Sent: 17 November 2020 07:21
To: Lua mailing list <>
Subject: EXT SENDER - Getting lua stack trace after a crash

We have a C/C++ application that embeds lua. Some of our business logic is in Lua. We use luabind to bind our C++ classes to Lua. If there is a crash, we would like to get a lua trace as well, to see what part of the business logic initiated the call into C++.

Has anyone tried to get a lua stack trace in the event of a crash in the C/C++ side in Windows/Linux? Say due to a nullptr. 
Do the normal Lua C APIs work for this if the crash was in some C++ code not related to lua or luabind - like if some C++ function was getting called and that had a bug?