1 // Copyright Daniel Wallin 2008. Use, modification and distribution is
2 // subject to the Boost Software License, Version 1.0. (See accompanying
3 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 #include <luabind/luabind.hpp>
7 #include <luabind/exception_handler.hpp>
9 struct my_exception
{};
11 void translate_my_exception(lua_State
* L
, my_exception
const&)
13 lua_pushstring(L
, "my_exception");
16 struct derived_std_exception
: std::exception
18 char const* what() const throw()
20 return "derived_std_exception";
24 void translate_derived_exception(lua_State
* L
, derived_std_exception
const&)
26 lua_pushstring(L
, "derived_std_exception");
36 throw derived_std_exception();
39 void test_main(lua_State
* L
)
41 using namespace luabind
;
43 register_exception_handler
<my_exception
>(&translate_my_exception
);
47 def("raise_derived", &raise_derived
)
51 "status, msg = pcall(raise)\n"
52 "assert(status == false)\n"
53 "assert(msg == 'my_exception')\n");
56 "status, msg = pcall(raise_derived)\n"
57 "assert(status == false)\n"
58 "assert(msg == 'std::exception: \\'derived_std_exception\\'')\n");
60 register_exception_handler
<derived_std_exception
>(&translate_derived_exception
);
63 "status, msg = pcall(raise_derived)\n"
64 "assert(status == false)\n"
65 "assert(msg == 'derived_std_exception')\n");