Add missing #undef N to constructor.hpp.
[luabind.git] / luabind / detail / constructor.hpp
blobf8b6f3f7afa5853781a9eb9f0565e054b637969d
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)
5 #if !BOOST_PP_IS_ITERATING
7 # ifndef LUABIND_DETAIL_CONSTRUCTOR_081018_HPP
8 # define LUABIND_DETAIL_CONSTRUCTOR_081018_HPP
10 # include <luabind/get_main_thread.hpp>
11 # include <luabind/object.hpp>
12 # include <luabind/wrapper_base.hpp>
13 # include <luabind/detail/inheritance.hpp>
15 # include <boost/preprocessor/iteration/iterate.hpp>
16 # include <boost/preprocessor/iteration/local.hpp>
17 # include <boost/preprocessor/repetition/enum_params.hpp>
18 # include <boost/preprocessor/repetition/enum_binary_params.hpp>
20 namespace luabind { namespace detail {
22 inline void inject_backref(lua_State*, void*, void*)
25 template <class T>
26 void inject_backref(lua_State* L, T* p, wrap_base*)
28 weak_ref(get_main_thread(L), 1).swap(wrap_access::ref(*p));
31 template <std::size_t Arity, class T, class Pointer, class Signature>
32 struct construct_aux;
34 template <class T, class Pointer, class Signature>
35 struct construct
36 : construct_aux<mpl::size<Signature>::value - 2, T, Pointer, Signature>
37 {};
39 template <class T, class Pointer, class Signature>
40 struct construct_aux<0, T, Pointer, Signature>
42 typedef pointer_holder<Pointer, T> holder_type;
44 void operator()(argument const& self_) const
46 object_rep* self = touserdata<object_rep>(self_);
47 class_rep* cls = self->crep();
49 std::auto_ptr<T> instance(new T);
50 inject_backref(self_.interpreter(), instance.get(), instance.get());
52 void* naked_ptr = instance.get();
53 Pointer ptr(instance.release());
55 void* storage = self->allocate(sizeof(holder_type));
57 self->set_instance(new (storage) holder_type(
58 ptr, registered_class<T>::id, naked_ptr, cls));
62 # define BOOST_PP_ITERATION_PARAMS_1 \
63 (3, (1, LUABIND_MAX_ARITY, <luabind/detail/constructor.hpp>))
64 # include BOOST_PP_ITERATE()
66 }} // namespace luabind::detail
68 # endif // LUABIND_DETAIL_CONSTRUCTOR_081018_HPP
70 #else // !BOOST_PP_IS_ITERATING
72 # define N BOOST_PP_ITERATION()
74 template <class T, class Pointer, class Signature>
75 struct construct_aux<N, T, Pointer, Signature>
77 typedef typename mpl::begin<Signature>::type first;
78 typedef typename mpl::next<first>::type iter0;
80 # define BOOST_PP_LOCAL_MACRO(n) \
81 typedef typename mpl::next< \
82 BOOST_PP_CAT(iter,BOOST_PP_DEC(n))>::type BOOST_PP_CAT(iter,n); \
83 typedef typename BOOST_PP_CAT(iter,n)::type BOOST_PP_CAT(a,BOOST_PP_DEC(n));
85 # define BOOST_PP_LOCAL_LIMITS (1,N)
86 # include BOOST_PP_LOCAL_ITERATE()
88 typedef pointer_holder<Pointer, T> holder_type;
90 void operator()(argument const& self_, BOOST_PP_ENUM_BINARY_PARAMS(N,a,_)) const
92 object_rep* self = touserdata<object_rep>(self_);
93 class_rep* cls = self->crep();
95 std::auto_ptr<T> instance(new T(BOOST_PP_ENUM_PARAMS(N,_)));
96 inject_backref(self_.interpreter(), instance.get(), instance.get());
98 void* naked_ptr = instance.get();
99 Pointer ptr(instance.release());
101 void* storage = self->allocate(sizeof(holder_type));
103 self->set_instance(new (storage) holder_type(
104 ptr, registered_class<T>::id, naked_ptr, cls));
108 # undef N
110 #endif