*** empty log message ***
[luabind.git] / src / function.cpp
blobabfe7ab14ee285a8223f1a1dd9c2699e3cdaf849
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.
23 #include <luabind/lua_include.hpp>
25 #define LUABIND_BUILDING
27 #include <luabind/luabind.hpp>
29 int luabind::detail::free_functions::function_dispatcher(lua_State* L)
31 function_rep* rep = static_cast<function_rep*>(lua_touserdata(L, lua_upvalueindex(1)));
33 std::size_t converter_storage[LUABIND_MAX_ARITY];
35 bool ambiguous = false;
36 int min_match = std::numeric_limits<int>::max();
37 int match_index = -1;
38 bool ret;
40 #ifdef LUABIND_NO_ERROR_CHECKING
42 if (rep->overloads().size() == 1)
44 match_index = 0;
46 else
49 #endif
50 int num_params = lua_gettop(L);
51 ret = find_best_match(L, &rep->overloads().front(), rep->overloads().size(), sizeof(free_functions::overload_rep), ambiguous, min_match, match_index, num_params);
53 #ifdef LUABIND_NO_ERROR_CHECKING
56 #else
58 if (!ret)
60 // this bock is needed to make sure the std::string is destructed
62 std::string msg = "no match for function call '";
63 msg += rep->name();
64 msg += "' with the parameters (";
65 msg += stack_content_by_name(L, 1);
66 msg += ")\ncandidates are:\n";
68 msg += get_overload_signatures(L, rep->overloads().begin(), rep->overloads().end(), rep->name());
70 lua_pushstring(L, msg.c_str());
73 lua_error(L);
76 if (ambiguous)
78 // this bock is needed to make sure the std::string is destructed
80 std::string msg = "call of overloaded function '";
81 msg += rep->name();
82 msg += "(";
83 msg += stack_content_by_name(L, 1);
84 msg += ") is ambiguous\nnone of the overloads have a best conversion:";
86 std::vector<const overload_rep_base*> candidates;
87 find_exact_match(L, &rep->overloads().front(), rep->overloads().size(), sizeof(free_functions::overload_rep), min_match, num_params, candidates);
89 msg += get_overload_signatures_candidates(L, candidates.begin(), candidates.end(), rep->name());
91 lua_pushstring(L, msg.c_str());
93 lua_error(L);
95 #endif
96 const overload_rep& ov_rep = rep->overloads()[match_index];
97 return ov_rep.call(L, ov_rep.fun, converter_storage);