lua-users home
lua-l archive

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

I wrote:
> I'll try it in the next days and let you know when I've added the
> required changes to the git repo.

Ok, I got it to work! Pull the newest update from the git repo and
follow these instructions:

1. This requires a DWARF2-enabled GCC 4.x for MinGW. The GCC from
the link you provided works fine. It doesn't work with the old
MinGW GCC 3.x which uses SJLJ unwinding.

2. First cleanup any old object files:

  mingw32-make clean

3. Recompile LuaJIT with frame unwind info and the shared libgcc.
The external unwinder must be explicitly enabled since this is not
the default on x86:

  mingw32-make "TARGET_CFLAGS=-funwind-tables -DLUAJIT_UNWIND_EXTERNAL" LDFLAGS=-shared-libgcc

4. Recompile *all* your C code (esp. modules loaded by Lua) with
-funwind-tables. No need to set this flag when compiling C++ code:

  gcc -Wall -O2 -fomit-frame-pointer -c foo.c -funwind-tables
  g++ -Wall -O2 -fomit-frame-pointer -c bar.cpp

5. Relink *all* your C code and C++ code with -shared-libgcc:

  gcc -shared -o foo.dll foo.o lua51.dll -shared-libgcc
  g++ -shared -o bar.dll bar.o lua51.dll -shared-libgcc

Test your setup first with:
  luajit -e "error('test')"
You should get a regular error message and a stack traceback.

Throwing/catching Lua errors or C++ exceptions should work now
between the two languages and even across DLLs. C++ destructors
are called as needed.

Bad things happen if you forget to recompile or relink any module.
If you throw an error across them you'll get a Lua PANIC message
or the dreaded "terminate called" message. wrote:
> One last question, can't it be solved like in the default lua
> vm, where the manual stack unwinding is repleaced by a c++ throw
> and catch expression and the whole vm is simply compilied as c++
> code? Or is that not possible because it is a jitter?

The relevant part of the code that sets up the catch frame is
written in assembler. Recompiling as C++ wouldn't help. Ditto for
the JIT-generated machine code.