[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Lua compiled as C++ and exceptions
- From: S <phd.st.p@...>
- Date: Thu, 17 Feb 2011 23:02:24 +0000
Hi,
first of all let me preliminary state that I am a Lua beginner :)
At the moment I am finding it difficult to have an embedded Lua
session (in a C++ session) throw an exception when an error is
encountered instead of just abruptly closing the running program.
To be more specific, I am using Visual Studio 2008, I downloaded Lua
5.1.4 and I modified the file luavs.bat to add the compiler options
/TP (compile as C++) and /EHsc (otherwise I get a warning: "C++
exception handler used, but unwind semantics are not enabled. Specify
/EHsc").
Then in the C++ program that uses a Lua session, I link to lua51.lib,
I make sure that lua51.dll can be found, and I include Lua via:
#include <lua.h>
(notice no extern "C").
This way it compiles, links and runs fine. However when I run the
following C++ code:
lua_State* L = lua_open();
lua_dofile(L, "file.lua");
and the script file.lua contains a syntax error, I get the following message:
Microsoft C++ exception: lua_jump at memory address.....
which for same reason I cannot catch even with:
catch(...) {...}
and the C++ program just plainly exit (which in my context is
something to be avoided at all costs).
To sum up, I need a way to make sure that all errors in Lua (which
may happen in say lua_dofile() or lua_call()) result in a
std::exception being thrown (which I will catch in my C++ code).
If it is possible, it would really help the debugging if an
informative message were included in the exception (like: "Parsing
error at line 24 of file.lua").
Any help / comment is greatly welcome.
Thank you