lua-users home
lua-l archive

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


On 04/06/2012 09:29 PM, Eric Wing wrote:

It should be enough to just push the error message as part of LUAI_TRY.
With C++ it would be something like:

#define LUAI_TRY(L,c,a) try { a } \
      catch(std::exception e) \
          { lua_pushstring(L, e.what()); (c)->status = -1; } \
      catch(...) \
          { if ((c)->status == 0) (c)->status = -1; }

--
- tom
telliamed@whoopdedo.org

Thanks for responding! I was having trouble with lua_pushstring not
doing anything for me. I think I finally figured out why.

I needed to change the status code from -1 to either LUA_ERRSYNTAX or
LUA_ERRRUN. Otherwise the string was getting lost. I found those two
cases in luaD_seterrorobj where the comment suggests it expects the
error message on the top.


I see. This was changed in Lua 5.2 which has a default case in seterrorobj.

It occurs to me that using a default catch is a bad idea. That should be "catch(lua_longjmp)" and the default will put a generic "unexpected error" message on the stack. Or don't handle it so it falls back to the host application. You just don't want some random exception to end up in seterrorobj which will try to access the top of the stack. That would be a bad thing if the exception occurred in "lib.unlock(password)"!

--
- tom
telliamed@whoopdedo.org