lua-users home
lua-l archive

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



On Thu, Jan 30, 2020 at 7:41 AM Viacheslav Usov <via.usov@gmail.com> wrote:
On Thu, Jan 30, 2020 at 4:26 PM Gisle Vanem <gvanem@yahoo.no> wrote:

>    #define LUA_API extern "C++"

The reason why I have settled on extern "C" is that I also use libraries built in C, which would otherwise be impossible to link with.


If you're mixing C and C++ interfaces throwing a Lua error becomes a problem:

- if you use 'longjmp' you don't perform proper stack unwinding and destruction in C++ code.
- if you use 'throw' the result is system dependent, the result of unwinding a stack with mixed C and C++ stack frames is probably not properly defined.

It may work on some platforms (like Windows with its structured exception handling), but it's not portable. C++ ABIs are also not the most stable, what works today may break tomorrow.

--