doc tweaks
[luabind.git] / luabind / detail / constructor.hpp
bloba09e00d3e3c2378ebca7809f8cf33827de9cdd04
1 // Copyright (c) 2003 Daniel Wallin and Arvid Norberg
3 // Permission is hereby granted, free of charge, to any person obtaining a
4 // copy of this software and associated documentation files (the "Software"),
5 // to deal in the Software without restriction, including without limitation
6 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
7 // and/or sell copies of the Software, and to permit persons to whom the
8 // Software is furnished to do so, subject to the following conditions:
10 // The above copyright notice and this permission notice shall be included
11 // in all copies or substantial portions of the Software.
13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
14 // ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
15 // TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
16 // PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
17 // SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
18 // ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
19 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
21 // OR OTHER DEALINGS IN THE SOFTWARE.
24 #if !BOOST_PP_IS_ITERATING
26 #ifndef LUABIND_CONSTRUCTOR_HPP_INCLUDED
27 #define LUABIND_CONSTRUCTOR_HPP_INCLUDED
29 #include <boost/config.hpp>
30 #include <boost/preprocessor/iterate.hpp>
31 #include <boost/preprocessor/repetition/enum.hpp>
32 #include <boost/preprocessor/repetition/enum_params.hpp>
33 #include <boost/preprocessor/repeat.hpp>
34 #include <boost/preprocessor/comma_if.hpp>
36 #include <luabind/config.hpp>
37 #include <luabind/detail/policy.hpp>
38 #include <luabind/detail/signature_match.hpp>
39 #include <luabind/detail/call_member.hpp>
41 namespace luabind { namespace detail
43 template<int N>
44 struct constructor_helper;
46 template<int N>
47 struct wrapped_constructor_helper;
49 #define BOOST_PP_ITERATION_PARAMS_1 (4, (0, LUABIND_MAX_ARITY, <luabind/detail/constructor.hpp>, 1))
50 #include BOOST_PP_ITERATE()
52 template<class T, class Policies, class ConstructorSig>
53 struct construct_class
55 inline static void* apply(lua_State* L)
57 typedef constructor_helper<ConstructorSig::arity> ConstrHelp;
58 typedef typename ConstrHelp::template apply<T> Caller;
59 return Caller::call(L, static_cast<const ConstructorSig*>(0), static_cast<const Policies*>(0));
63 template<class T, class Policies, class ConstructorSig>
64 struct construct_wrapped_class
66 inline static void* apply(lua_State* L, lua_reference const& ref)
68 typedef wrapped_constructor_helper<ConstructorSig::arity> ConstrHelp;
69 typedef typename ConstrHelp::apply<T> Caller;
70 return Caller::call(L, ref, static_cast<const ConstructorSig*>(0), static_cast<const Policies*>(0));
76 #endif // LUABIND_CONSTRUCTOR_HPP_INCLUDED
79 #elif BOOST_PP_ITERATION_FLAGS() == 1
82 #define LUABIND_DECL(z, n, text) typedef typename find_conversion_policy<n+1,Policies>::type BOOST_PP_CAT(converter_policy,n); \
83 typedef typename BOOST_PP_CAT(converter_policy,n)::template generate_converter<A##n, lua_to_cpp>::type BOOST_PP_CAT(c_t,n); \
84 typename BOOST_PP_CAT(converter_policy,n)::template generate_converter<A##n, lua_to_cpp>::type BOOST_PP_CAT(c,n);
85 #define LUABIND_PARAM(z,n,text) BOOST_PP_CAT(c,n).BOOST_PP_CAT(c_t,n)::apply(L, LUABIND_DECORATE_TYPE(A##n), n + 2)
87 template<>
88 struct constructor_helper<BOOST_PP_ITERATION()>
90 template<class T>
91 struct apply
93 template<class Policies, BOOST_PP_ENUM_PARAMS(LUABIND_MAX_ARITY, class A)>
94 static T* call(lua_State* L, const constructor<BOOST_PP_ENUM_PARAMS(LUABIND_MAX_ARITY,A)>*, const Policies*)
96 // L is used, but the metrowerks compiler warns about this before expanding the macros
97 L = L;
98 BOOST_PP_REPEAT(BOOST_PP_ITERATION(), LUABIND_DECL, _)
99 return new T(BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_PARAM, _));
104 template<>
105 struct wrapped_constructor_helper<BOOST_PP_ITERATION()>
107 template<class T>
108 struct apply
110 template<class Policies, BOOST_PP_ENUM_PARAMS(LUABIND_MAX_ARITY, class A)>
111 static T* call(lua_State* L, lua_reference const& ref, const constructor<BOOST_PP_ENUM_PARAMS(LUABIND_MAX_ARITY,A)>*, const Policies*)
113 BOOST_PP_REPEAT(BOOST_PP_ITERATION(), LUABIND_DECL, _)
114 return new T(luabind::object(L, ref, true/*luabind::object::reference()*/) BOOST_PP_COMMA_IF(BOOST_PP_ITERATION()) BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_PARAM, _));
120 #undef LUABIND_PARAM
121 #undef LUABIND_DECL
123 #endif // LUABIND_CONSTRUCTOR_HPP_INCLUDED