Revert 5134297. This caused overload ambiguities.
[luabind.git] / src / class_info.cpp
blob57b5260f6b469bb1cf55d6aca726323fd76ffb0f
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 #define LUABIND_BUILDING
25 #include <luabind/lua_include.hpp>
27 #include <luabind/luabind.hpp>
28 #include <luabind/class_info.hpp>
30 namespace luabind
32 LUABIND_API class_info get_class_info(argument const& o)
34 lua_State* L = o.interpreter();
36 o.push(L);
37 detail::object_rep* obj = detail::is_class_object(L, -1);
39 if (!obj)
41 class_info result;
42 result.name = lua_typename(L, -1);
43 lua_pop(L, 1);
44 result.methods = newtable(L);
45 result.attributes = newtable(L);
46 return result;
49 lua_pop(L, 1);
51 obj->crep()->get_table(L);
52 object table(from_stack(L, -1));
53 lua_pop(L, 1);
55 class_info result;
56 result.name = obj->crep()->name();
57 result.methods = newtable(L);
58 result.attributes = newtable(L);
60 std::size_t index = 1;
62 for (iterator i(table), e; i != e; ++i)
64 if (type(*i) != LUA_TFUNCTION)
65 continue;
67 // We have to create a temporary `object` here, otherwise the proxy
68 // returned by operator->() will mess up the stack. This is a known
69 // problem that probably doesn't show up in real code very often.
70 object member(*i);
71 member.push(L);
72 detail::stack_pop pop(L, 1);
74 if (lua_tocfunction(L, -1) == &detail::property_tag)
76 result.attributes[index++] = i.key();
78 else
80 result.methods[i.key()] = *i;
84 return result;
87 LUABIND_API void bind_class_info(lua_State* L)
89 module(L)
91 class_<class_info>("class_info_data")
92 .def_readonly("name", &class_info::name)
93 .def_readonly("methods", &class_info::methods)
94 .def_readonly("attributes", &class_info::attributes),
96 def("class_info", &get_class_info)