Fix bug when passing type with holder by value to Lua.
[luabind.git] / src / wrapper_base.cpp
blobc5296f0865af9b96a23af92cc99d1eb18e23f0e5
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/config.hpp>
24 #include <luabind/lua_include.hpp>
25 #include <luabind/detail/object_rep.hpp>
26 #include <luabind/detail/class_rep.hpp>
27 #include <luabind/detail/stack_utils.hpp>
29 namespace luabind { namespace detail
31 LUABIND_API void do_call_member_selection(lua_State* L, char const* name)
33 object_rep* obj = static_cast<object_rep*>(lua_touserdata(L, -1));
34 lua_pop(L, 1); // pop self
36 obj->crep()->get_table(L); // push the crep table
37 lua_pushstring(L, name);
38 lua_gettable(L, -2);
39 lua_remove(L, -2); // remove the crep table
42 if (!lua_iscfunction(L, -1)) return;
43 if (lua_getupvalue(L, -1, 3) == 0) return;
44 detail::stack_pop p(L, 1);
45 if (lua_touserdata(L, -1) != reinterpret_cast<void*>(0x1337)) return;
48 // this (usually) means the function has not been
49 // overridden by lua, call the default implementation
50 lua_pop(L, 1);
51 obj->crep()->get_default_table(L); // push the crep table
52 lua_pushstring(L, name);
53 lua_gettable(L, -2);
54 assert(!lua_isnil(L, -1));
55 lua_remove(L, -2); // remove the crep table