lua-users home
lua-l archive

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


>  > As you know, compiling Lua as C++ basically changes longjmp() in
>  > LUAI_THROW to throw; and setjmp() in LUAI_TRY to try {} catch() {}.
>  > This change is crucial as longjmp/setjmp basically do not call any
>  > destructors in C++ objects.
>
>  That's only part of the problem. The other issue is that throwing
>  a C++ error "across" a C++ -> Lua -> C++ call chain would leave
>  Lua in an inconsistent state.

Hmm. I naively thought that that try/catch in LUAI_TRY deals with that issue.

<...>

>  Enabling
>  GCC's exception handling causes considerable bloat in the
>  executables and catch(...) has it's own share of problems.

Well, we use exceptions in our C++ code anyway.

<...>

>  Well, this is a matter of resources for me, too. I've already
>  researched how to pass the necessary info to the GCC unwinder at
>  runtime. Unfortunately, this is quite complicated and would take
>  a lot of time to implement. I'm not sure it's worth the effort to
>  add this to the LuaJIT 1.x branch.

I see. Am I correct that the only feasible option for us at the moment
is to compile LuaJIT as plain C and to rewrite all our bindings as
follows:

int my_binding(lua_State * L)
{
  // Work with Lua: get arguments etc
  try
  {
     // Do the job
  }
  catch (std::exception & e)
  {
     return luaL_error("unhandled exception: %s", s.what());
  }
  catch (...)
  {
    ExitWithFatalError(); // As it would catch SEH exceptions under Windows.
  }
  // Push return values
  return N;
}

(Probably messed some details in the morning, sorry.)

Thank you for detailed answer.
Alexander.