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/get_main_thread.hpp>
9 # include <luabind/handle.hpp>
10 # include <luabind/detail/policy.hpp>
11 # include <boost/shared_ptr.hpp>
18 struct shared_ptr_deleter
20 shared_ptr_deleter(lua_State
* L
, int index
)
21 : life_support(get_main_thread(L
), index
)
24 void operator()(void const*)
26 handle().swap(life_support
);
35 struct default_converter
<boost::shared_ptr
<T
> >
36 : default_converter
<T
*>
38 typedef boost::mpl::false_ is_native
;
41 int match(lua_State
* L
, U
, int index
)
43 return default_converter
<T
*>::match(
44 L
, LUABIND_DECORATE_TYPE(T
*), index
);
48 boost::shared_ptr
<T
> apply(lua_State
* L
, U
, int index
)
50 T
* raw_ptr
= default_converter
<T
*>::apply(
51 L
, LUABIND_DECORATE_TYPE(T
*), index
);
53 return boost::shared_ptr
<T
>();
54 return boost::shared_ptr
<T
>(
55 raw_ptr
, detail::shared_ptr_deleter(L
, index
));
58 void apply(lua_State
* L
, boost::shared_ptr
<T
> const& p
)
60 if (detail::shared_ptr_deleter
* d
=
61 boost::get_deleter
<detail::shared_ptr_deleter
>(p
))
63 d
->life_support
.push(L
);
67 detail::value_converter().apply(L
, p
);
72 void converter_postcall(lua_State
*, U
const&, int)
77 struct default_converter
<boost::shared_ptr
<T
> const&>
78 : default_converter
<boost::shared_ptr
<T
> >
81 } // namespace luabind
83 #endif // LUABIND_SHARED_PTR_CONVERTER_090211_HPP