1 // Copyright Daniel Wallin 2008. 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)
4 
5 #ifndef LUABIND_COPY_POLICY_081021_HPP
6 # define LUABIND_COPY_POLICY_081021_HPP
7 
8 # include <luabind/detail/policy.hpp>
9 
10 namespace luabind {
11 
12 namespace detail
13 {
14 
15   struct copy_converter
16   {
17       template <class T>
applyluabind::detail::copy_converter18       void apply(lua_State* L, T const& x)
19       {
20           value_converter().apply(L, x);
21       }
22 
23       template <class T>
applyluabind::detail::copy_converter24       void apply(lua_State* L, T* x)
25       {
26           if (!x)
27               lua_pushnil(L);
28           else
29               apply(L, *x);
30       }
31   };
32 
33   template <int N>
34   struct copy_policy : conversion_policy<N>
35   {
precallluabind::detail::copy_policy36       static void precall(lua_State*, index_map const&)
37       {}
38 
postcallluabind::detail::copy_policy39       static void postcall(lua_State*, index_map const&)
40       {}
41 
42       template <class T, class Direction>
43       struct apply
44       {
45           typedef copy_converter type;
46       };
47   };
48 
49 } // namespace detail
50 
51 template <int N>
52 detail::policy_cons<detail::copy_policy<N>, detail::null_type>
copy(LUABIND_PLACEHOLDER_ARG (N))53 copy(LUABIND_PLACEHOLDER_ARG(N))
54 {
55     return detail::policy_cons<detail::copy_policy<N>, detail::null_type>();
56 }
57 
58 } // namespace luabind
59 
60 #endif // LUABIND_COPY_POLICY_081021_HPP
61