5 struct ex
: public std::exception
7 ex(const char* m
): msg(m
) {}
8 virtual const char* what() const throw() { return msg
; }
12 struct exception_thrower
14 exception_thrower() {}
15 exception_thrower(int) { throw ex("exception description"); }
16 exception_thrower(int, int) { throw "a string exception"; }
17 exception_thrower(int, int, int) { throw 10; }
18 int f() { throw ex("exception from a member function"); }
19 int g() { throw "a string exception"; }
23 } // anonymous namespace
26 bool test_exceptions()
30 using namespace luabind
;
32 lua_State
* L
= lua_open();
34 int top
= lua_gettop(L
);
38 class_
<exception_thrower
>(L
, "exception_thrower")
40 .def(constructor
<int>())
41 .def(constructor
<int, int>())
42 .def(constructor
<int, int, int>())
43 .def("f", &exception_thrower::f
)
44 .def("g", &exception_thrower::g
)
45 .def("h", &exception_thrower::h
);
47 if (dostring2(L
, "a = exception_thrower(1)") != 1) throw 0;
48 if (std::string("exception description") != lua_tostring(L
, -1)) throw 0;
50 if (dostring2(L
, "a = exception_thrower(1,1)") != 1) throw 0;
51 if (std::string("a string exception") != lua_tostring(L
, -1)) throw 0;
53 if (dostring2(L
, "a = exception_thrower(1,1,1)") != 1) throw 0;
54 if (std::string("exception_thrower() threw an exception") != lua_tostring(L
, -1)) throw 0;
56 if (dostring2(L
, "a = exception_thrower()") != 0) throw 0;
57 if (dostring2(L
, "a:f()") != 1) throw 0;
58 if (std::string("exception from a member function") != lua_tostring(L
, -1)) throw 0;
60 if (dostring2(L
, "a:g()") != 1) throw 0;
61 if (std::string("a string exception") != lua_tostring(L
, -1)) throw 0;
63 if (dostring2(L
, "a:h()") != 1) throw 0;
64 if (std::string("exception_thrower:h() threw an exception") != lua_tostring(L
, -1)) throw 0;
67 if (top
!= lua_gettop(L
)) return false;