lua-users home
lua-l archive

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

Thanks Mark and Miles!

Here's an example of what I am wrapping with SWIG:

    inline const double GetVi (const unsigned int index) const { return (index); }
    inline const double GetXi (const unsigned int index) const { return (index); }
    inline const double GetYi (const unsigned int index) const { return (index); }
    inline const double GetZi (const unsigned int index) const { return (index); }

If index is out of range, it will throw an exception causing my program to core.  I have a try/catch (...) around the call to:

    errorCode = lua_pcall ((lua_State *) _LState, 0, LUA_MULTRET, 0);

However, my exception handler is never reached.  

Should that work for me?  I may be missing something...


On Mar 5, 2008, at 6:47 PM, Mark Gossage wrote:

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.:

}catch(some_exception& e){

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.


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.



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