lua-users home
lua-l archive

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


Hello Joey,

The current way of SWIG handling exceptions is to convert
the exception into a string and push it as a lua_error.
It looks a little like this.:

try{
some_method();
}catch(some_exception& e){
lua_pushString(L,tostring(e));
lua_error(L);
}

The issue is that Lua uses longjmp for its errors and they
don't work well with exceptions.

SWIG used to make copies of the exception object and return
it back to the interpreter. However if the object doesn't
have a copy constructor this fails.

If you wanted to change the behaviour, the way to do it
would be to write a new typemap for it.
The default code is found in lua.swg, you could add to this if
you wanted.
What I suggest is, send me a sample of the code you want
to work on, and I can suggest some ideas, at the same time
I will update the SWIG documentation.

Regards,
Mark

==============
I was searching the list about C++ exceptions and Lua and found lots
of different methods for adding C++ exception support to support home-
grown binding and toLua++. However, there is nothing for SWIG.

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.

Thanks!

Joey


Yahoo! Answers - Get better answers from someone who knows. Try it now.