lua-users home
lua-l archive

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


> The vector's destructor never gets called and its memory is leaked.

If you compile Lua as C++ code, it is not difficult to change it
to use real exceptions instead of setjmp/longjmp. Lua 5.1 will have
a compilation flag for that. I hope the next lines give the
general idea:

>  #ifndef LUA_USEEXCEPTIONS
>
>  #define L_THROW(c)      longjmp((c)->b, 1)
>  #define L_TRY(c,a)      if (setjmp((c)->b) == 0) { a }
>
>  #else
>
>  #define L_THROW(c)      throw(c)
>  #define L_TRY(c,a)      try { a } catch(...) \
>                                  { if ((c)->status == 0) (c)->status = -1; }
>
>  #endif

This is not a perfect solution (other C++ exceptions are also catched
by Lua protected calls), but it seems to work ok.

-- Roberto