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.
28 #include <luabind/luabind.hpp>
30 int luabind::detail::free_functions::function_dispatcher(lua_State
* L
)
32 function_rep
* rep
= static_cast<function_rep
*>(lua_touserdata(L
, lua_upvalueindex(1)));
34 bool ambiguous
= false;
35 int min_match
= std::numeric_limits
<int>::max();
39 #ifdef LUABIND_NO_ERROR_CHECKING
41 if (rep
->overloads().size() == 1)
49 int num_params
= lua_gettop(L
);
50 ret
= find_best_match(L
, &rep
->overloads().front(), rep
->overloads().size(), sizeof(free_functions::overload_rep
), ambiguous
, min_match
, match_index
, num_params
);
52 #ifdef LUABIND_NO_ERROR_CHECKING
59 // this bock is needed to make sure the std::string is destructed
61 std::string msg
= "no match for function call '";
63 msg
+= "' with the parameters (";
64 msg
+= stack_content_by_name(L
, 1);
65 msg
+= ")\ncandidates are:\n";
67 msg
+= get_overload_signatures(L
, rep
->overloads().begin(), rep
->overloads().end(), rep
->name());
69 lua_pushstring(L
, msg
.c_str());
77 // this bock is needed to make sure the std::string is destructed
79 std::string msg
= "call of overloaded function '";
82 msg
+= stack_content_by_name(L
, 1);
83 msg
+= ") is ambiguous\nnone of the overloads have a best conversion:";
85 std::vector
<const overload_rep_base
*> candidates
;
86 find_exact_match(L
, &rep
->overloads().front(), rep
->overloads().size(), sizeof(free_functions::overload_rep
), min_match
, num_params
, candidates
);
88 msg
+= get_overload_signatures_candidates(L
, candidates
.begin(), candidates
.end(), rep
->name());
90 lua_pushstring(L
, msg
.c_str());
95 const overload_rep
& ov_rep
= rep
->overloads()[match_index
];
96 return ov_rep
.call(L
, ov_rep
.fun
);