Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the benefit to compile Lua as C++ other than avoid 'extern C' and get 'C++ exception'?

Tags:

c++

lua

I'm quite new in Lua, and I want to embed Lua into our game project using C++. The first thing I notice, Lua is allowed to be compiled as C++ code, and from the doc, I've learned that this will eliminate the 'extern C' wrapping around Lua's headers, and also the error handling will be C++ exception instead of longjump/setjump.

My question is, besides these two differences, is there any other real benefit to compile Lua code as C++ code? These two don't real convince me, as, 1) it doesn't bother me to wrap c headers with 'extern C', 2) our project doesn't allow exception, so I have to change in luaconf.h to use longjump/setjump any way.

like image 632
frank28_nfls Avatar asked Dec 06 '11 12:12

frank28_nfls


1 Answers

Those are the benefits of compiling Lua as C++. The extern "C" thing isn't even really the point; it's all about exception handling. And while your application forbids exceptions, not every C++ application does.

If you're using all of C++, you either have to take steps to prevent exceptions from passing through Lua (not the easiest thing in the world unless you're using a wrapper like Luabind) or to compile Lua as C++.

There are no other benefits of compiling Lua as C++. Exception handling is the reason why Lua can be compiled as C++.

like image 106
Nicol Bolas Avatar answered Nov 15 '22 11:11

Nicol Bolas