// Copyright Daniel Wallin 2009. Use, modification and distribution is // subject to the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) #ifndef LUABIND_SHARED_PTR_CONVERTER_090211_HPP # define LUABIND_SHARED_PTR_CONVERTER_090211_HPP # include # include # include # include namespace luabind { namespace detail { struct shared_ptr_deleter { shared_ptr_deleter(lua_State* L, int index) : life_support(get_main_thread(L), L, index) {} void operator()(void const*) { handle().swap(life_support); } handle life_support; }; } // namespace detail template struct default_converter > : default_converter { typedef boost::mpl::false_ is_native; template int match(lua_State* L, U, int index) { return default_converter::match( L, LUABIND_DECORATE_TYPE(T*), index); } template boost::shared_ptr apply(lua_State* L, U, int index) { T* raw_ptr = default_converter::apply( L, LUABIND_DECORATE_TYPE(T*), index); if (!raw_ptr) return boost::shared_ptr(); return boost::shared_ptr( raw_ptr, detail::shared_ptr_deleter(L, index)); } void apply(lua_State* L, boost::shared_ptr const& p) { if (detail::shared_ptr_deleter* d = boost::get_deleter(p)) { d->life_support.push(L); } else { detail::value_converter().apply(L, p); } } template void converter_postcall(lua_State*, U const&, int) {} }; template struct default_converter const&> : default_converter > {}; } // namespace luabind #endif // LUABIND_SHARED_PTR_CONVERTER_090211_HPP