[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: RE: Binding C++ functions that 'throw' exceptions
- From: "Erik Cassel" <erik@...>
- Date: Thu, 16 Aug 2007 19:54:21 -0700
Perhaps this is relevant:
"This lets me throw an std::exception-derived object from anywhere
in C++ code. Lua will catch it and translate it appropriately in
Also, Lua uses an std::exception-derived class to throw Lua errors.
This means I can catch errors thrown by Lua (as in lua_touserdata)."
Sample source code is here:
Greg Falcon found a bug in my solution, which he documents here:
http://lua-users.org/lists/lua-l/2006-03/msg00735.html. Fortunately, the bug
can be fixed by defining a copy constructor. If you're interested I can post
the code that we use in production.
[mailto:firstname.lastname@example.org] On Behalf Of RJP Computing
Sent: Thursday, August 16, 2007 11:01 AM
To: Lua list
Subject: Binding C++ functions that 'throw' exceptions
I am using toLua++ to bind a bunch of functions and many of them throw
exceptions. Lua / toLua doesn't allow the exception to come back to C++
after it happens. Instead Lua / toLua reports "Cannot convert value to
string" which is not useful. I need to have the exception to go to my main
application that knows how to deal with that type of exception. Or I need to
have the exception re-bundled as a lua_error. I am using Gcc for the
compiler on Windows. If I don't compile Lua as C++ I don't get anything
except a close of my program. It appears the Gcc has a problem bridging the
gap between C and C++ when exceptions are thrown. Are there any ideas on if
this can be automated? I don't want to write all the bindings by hand and I
have to deal with exceptions.
Now I have created bindings by hand and I can properly catch the exception
inside the binding function. All I do with the exception is get the
exceptions description and call luaL_error( description ). This works
flawlessly. I basically am asking if there is a way to make the generated
functions generate try/catch blocks in the generated functions. Or to push
the error message from my exception on to the stack so that when lua_pcall()
returns it's error number the message will be on the stack as it usually
I hope this made sense. Please ask if you need clarification.