lua-users home
lua-l archive

Re: SWIG, C++ Exceptions, and Lua

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


Joey Mukherjee <joey@swri.edu> writes:
> Is it possible to make SWIG and Lua work well with C++ exceptions? If
> so, what is the best way?
>
> Really, the only thing I need is for Lua to not swallow my exceptions
> and allow the exception to pass through to main program.
Hmm maybe I mis-understand the problem, but everything seems to work ok
for me...
swig just throws a normal lua error for its errors, and in my program,
my "top-level" calls into Lua use a function like this:
 static void
 do_call (lua_State *L, int nargs, int nres)
 {
 int err = lua_pcall (L, nargs, nres, 0);
 if (err)
 {
 string err_str = lua_tostring (L, -1);
 throw file_error (err_str);
 }
 }
So any error swig signals will cause that pcall to return an error, and
the above function will turn that into a C++ exception...
-Miles
-- 
Religion, n. A daughter of Hope and Fear, explaining to Ignorance the nature
of the Unknowable.

AltStyle によって変換されたページ (->オリジナル) /