Add make_instance() helper function.
[luabind.git] / luabind / tag_function.hpp
blob51fe97b751f67084e4f4ecf9754f7be1274a1460
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_TAG_FUNCTION_081129_HPP
8 # define LUABIND_TAG_FUNCTION_081129_HPP
10 # if LUABIND_MAX_ARITY <= 8
11 # include <boost/mpl/vector/vector10.hpp>
12 # else
13 # include <boost/mpl/vector/vector50.hpp>
14 # endif
15 # include <boost/preprocessor/cat.hpp>
16 # include <boost/preprocessor/iterate.hpp>
17 # include <boost/preprocessor/repetition/enum_params.hpp>
18 # include <boost/preprocessor/repetition/enum_trailing_params.hpp>
20 namespace luabind {
22 namespace detail
25 template <class Signature, class F>
26 struct tagged_function
28 tagged_function(F f)
29 : f(f)
32 F f;
35 template <class Signature, class F>
36 Signature deduce_signature(tagged_function<Signature, F> const&, ...)
38 return Signature();
41 template <class Signature, class F, class Policies>
42 int invoke(
43 lua_State* L, function_object const& self, invoke_context& ctx
44 , tagged_function<Signature, F> const& tagged
45 , Signature, Policies const& policies)
47 return invoke(L, self, ctx, tagged.f, Signature(), policies);
50 template <class Function>
51 struct signature_from_function;
53 # define BOOST_PP_ITERATION_PARAMS_1 \
54 (3, (0, LUABIND_MAX_ARITY, <luabind/tag_function.hpp>))
55 # include BOOST_PP_ITERATE()
57 } // namespace detail
59 template <class Signature, class F>
60 detail::tagged_function<
61 typename detail::signature_from_function<Signature>::type
62 , F
64 tag_function(F f)
66 return f;
69 } // namespace luabind
71 # endif // LUABIND_TAG_FUNCTION_081129_HPP
73 #else // BOOST_PP_IS_ITERATING
75 # define N BOOST_PP_ITERATION()
76 # define NPLUS1 BOOST_PP_INC(N)
78 template <class R BOOST_PP_ENUM_TRAILING_PARAMS(N, class A)>
79 struct signature_from_function<R(BOOST_PP_ENUM_PARAMS(N, A))>
81 typedef BOOST_PP_CAT(mpl::vector, NPLUS1)<
82 R BOOST_PP_ENUM_TRAILING_PARAMS(N, A)
83 > type;
86 #endif // BOOST_PP_IS_ITERATING