1 // Copyright Daniel Wallin 2009. 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_SHARED_PTR_CONVERTER_090211_HPP
6 # define LUABIND_SHARED_PTR_CONVERTER_090211_HPP
8 # include <luabind/handle.hpp>
9 # include <luabind/detail/policy.hpp>
10 # include <boost/shared_ptr.hpp>
17 struct shared_ptr_deleter
19 shared_ptr_deleter(lua_State
* L
, int index
)
20 : life_support(L
, index
)
23 void operator()(void const*)
25 handle().swap(life_support
);
34 struct default_converter
<boost::shared_ptr
<T
> >
35 : default_converter
<T
*>
37 typedef boost::mpl::false_ is_native
;
40 int match(lua_State
* L
, U
, int index
)
42 return default_converter
<T
*>::match(
43 L
, LUABIND_DECORATE_TYPE(T
*), index
);
47 boost::shared_ptr
<T
> apply(lua_State
* L
, U
, int index
)
49 T
* raw_ptr
= default_converter
<T
*>::apply(
50 L
, LUABIND_DECORATE_TYPE(T
*), index
);
52 return boost::shared_ptr
<T
>();
53 return boost::shared_ptr
<T
>(
54 raw_ptr
, detail::shared_ptr_deleter(L
, index
));
57 void apply(lua_State
* L
, boost::shared_ptr
<T
> const& p
)
59 if (detail::shared_ptr_deleter
* d
=
60 boost::get_deleter
<detail::shared_ptr_deleter
>(p
))
62 d
->life_support
.push(L
);
66 detail::value_converter().apply(L
, p
);
71 void converter_postcall(lua_State
*, U
const&, int)
76 struct default_converter
<boost::shared_ptr
<T
> const&>
77 : default_converter
<boost::shared_ptr
<T
> >
80 } // namespace luabind
82 #endif // LUABIND_SHARED_PTR_CONVERTER_090211_HPP