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_COMPUTE_RANK_081006_HPP
6 # define LUABIND_COMPUTE_RANK_081006_HPP
7 
8 # include <luabind/config.hpp>
9 # include <luabind/detail/policy.hpp>
10 # include <boost/mpl/apply_wrap.hpp>
11 # include <boost/mpl/begin_end.hpp>
12 # include <boost/mpl/int.hpp>
13 # include <boost/mpl/next.hpp>
14 
15 namespace luabind { namespace detail {
16 
17 namespace mpl = boost::mpl;
18 
19 template <class Idx, class Iter, class End, class Policies>
compute_score_aux(lua_State * L,int index,Idx,Iter,End end,Policies const & policies)20 int compute_score_aux(
21     lua_State*L, int index, Idx, Iter, End end, Policies const& policies)
22 {
23     typedef typename Iter::type arg_type;
24     typedef typename find_conversion_policy<Idx::value, Policies>::type
25         conversion_policy;
26     typedef typename mpl::apply_wrap2<
27         conversion_policy, arg_type, lua_to_cpp>::type converter;
28 
29     int score = converter::match(L, LUABIND_DECORATE_TYPE(arg_type), index);
30 
31     if (score < 0)
32         return score;
33 
34     if (conversion_policy::has_arg)
35         ++index;
36 
37     int next = compute_score_aux(
38         L
39       , index
40       , typename mpl::next<Idx>::type()
41       , typename mpl::next<Iter>::type()
42       , end
43       , policies
44     );
45 
46     if (next < 0)
47         return next;
48 
49     return score + next;
50 }
51 
52 template <class Idx, class End, class Policies>
compute_score_aux(lua_State *,int,Idx,End,End,Policies const &)53 int compute_score_aux(lua_State*, int, Idx, End, End, Policies const&)
54 {
55     return 0;
56 }
57 
58 template <class Signature, class Policies>
compute_score(lua_State * L,Signature,Policies const & policies)59 int compute_score(lua_State* L, Signature, Policies const& policies)
60 {
61     return compute_score_aux(
62         L
63       , 1
64       , mpl::int_<1>()
65       , typename mpl::next<typename mpl::begin<Signature>::type>::type()
66       , typename mpl::end<Signature>::type()
67       , policies
68     );
69 }
70 
71 }} // namespace luabind::detail
72 
73 #endif // LUABIND_COMPUTE_RANK_081006_HPP
74