C++ exceptions

  • From: Alex Guo <chessnut@xxxxxxxxxxx>
  • To: "luajit@xxxxxxxxxxxxx" <luajit@xxxxxxxxxxxxx>
  • Date: Mon, 13 Jul 2015 14:27:56 -0400

Hi,
Sorry if this is a FAQ -- I tried my best to make sure the question wasn't
already clearly answered. After many hours of browsing through any relevant web
page I could find, I've decided to post to the mailing list.
The problem I'm trying to solve is throwing C++ exceptions. Here is some sample
code that works in a small C++ unit test, but fails in a large C++ code base
(40k LOC, linked against several other binaries that exceed several hundred
thousand LOC).
lua_State *my_lua = lua_open();
try {
int result = luaL_dostring(my_lua, "end end end end end");
LOG(INFO) << "Lua result: " << result;
lua_error(my_lua);
} catch (std::exception& err) {
LOG(INFO) << "Oops: " << err.what();
}
lua_close(my_lua);
To solve the problem, I thought the issue was that I needed to compile LuaJIT
with a C++ compiler. However, now I'm starting to realize that it might be the
case that LuaJIT is supposed to support C++ exceptions even if built with a C
compiler. Also, building LuaJIT with a C++ compiler is simply not supported.
However, I didn't find these thoughts explicitly mentioned anywhere on the
LuaJIT home page....if I missed it, kindly let me know.
I'm statically linking LuaJIT-2.0.4, with clang++ 3.6.1.
Thanks for any help,Alex Guo

Other related posts: