lua-users home
lua-l archive

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

On 18/10/10 14:48, Mike Pall wrote:
> Andrea wrote:
>> The problem is that Visual Studio reports that the 2nd exception
>> is unhandled and basically ignores it.
>> This works fine with Lua (non jit).
> Well, looks like the SEH chains got messed up on Windows/x86. :-(

I thought it was something like that. No idea though how it works.

> Lua uses setjmp/longjmp from MSVC. Even though MSDN suggests that
> mixing this with C++ exceptions is not safe, the longjmp from MSVC
> cleans up the SEH chain. But I can't use setjmp/longjmp in LuaJIT.

At some point I even tried to compile LuaJIT as C++ with a long list of compiler errors, and I
suspect it is not the right thing to do.

> Your options are:
> - Wrap the try/catch in a separate C++ function declared as
>   __declspec(noinline). Call that from a function without
>   try/catch and then run lua_error() from there.
> - Use either Linux or Windows/x64 which have much better C++
>   exception handling interoperability.

In the end I have 3 functions

1) the original C++ function that throws
2) a wrapper that convert exceptions into c-style return code
3) the actual function calling 2+1 and lua_error

with a macro steps 2 and 3 are hidden from the developer and
I did not notice any measurable speed change.