1 // Copyright Daniel Wallin 2005. 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)
5 #ifndef LUABIND_EXCEPTION_HANDLER_050601_HPP
6 # define LUABIND_EXCEPTION_HANDLER_050601_HPP
8 # include <luabind/lua_include.hpp>
9 # include <luabind/config.hpp>
10 # include <boost/optional.hpp>
11 # include <boost/type.hpp>
13 # if BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
14 # include <boost/mpl/if.hpp>
15 # include <boost/type_traits/is_pointer.hpp>
20 # ifndef LUABIND_NO_EXCEPTIONS
25 struct LUABIND_API exception_handler_base
27 exception_handler_base()
31 virtual ~exception_handler_base() {}
32 virtual void handle(lua_State
*) const = 0;
34 void try_next(lua_State
*) const;
36 exception_handler_base
* next
;
39 namespace mpl
= boost::mpl
;
41 template<class E
, class Handler
>
42 struct exception_handler
: exception_handler_base
44 # if BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
45 typedef typename
mpl::if_
<
46 boost::is_pointer
<E
>, E
, E
const&
49 typedef E
const& argument
;
52 exception_handler(Handler handler
)
56 void handle(lua_State
* L
) const
71 LUABIND_API
void handle_exception_aux(lua_State
* L
);
72 LUABIND_API
void register_exception_handler(exception_handler_base
*);
78 template<class E
, class Handler
>
79 void register_exception_handler(Handler handler
, boost::type
<E
>* = 0)
81 # ifndef LUABIND_NO_EXCEPTIONS
82 detail::register_exception_handler(
83 new detail::exception_handler
<E
, Handler
>(handler
)
88 template<class R
, class F
>
89 boost::optional
<R
> handle_exceptions(lua_State
* L
, F fn
, boost::type
<R
>* = 0)
91 # ifndef LUABIND_NO_EXCEPTIONS
98 detail::handle_exception_aux(L
);
101 return boost::optional
<R
>();
107 } // namespace luabind
109 #endif // LUABIND_EXCEPTION_HANDLER_050601_HPP