Fix bug when passing type with holder by value to Lua.
[luabind.git] / luabind / detail / class_registry.hpp
blob766c9394985c748546c7a428ea40206502cf6658
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.
24 #ifndef LUABIND_CLASS_REGISTRY_HPP_INCLUDED
25 #define LUABIND_CLASS_REGISTRY_HPP_INCLUDED
27 #include <typeinfo>
28 #include <map>
30 #include <luabind/config.hpp>
31 #include <luabind/open.hpp>
33 namespace luabind { namespace detail
35 class class_rep;
37 struct LUABIND_API class_registry
39 class_registry(lua_State* L);
41 static class_registry* get_registry(lua_State* L);
43 int cpp_instance() const { return m_cpp_instance_metatable; }
44 int cpp_class() const { return m_cpp_class_metatable; }
46 int lua_instance() const { return m_lua_instance_metatable; }
47 int lua_class() const { return m_lua_class_metatable; }
48 int lua_function() const { return m_lua_function_metatable; }
50 void add_class(LUABIND_TYPE_INFO info, class_rep* crep);
52 struct cmp
54 bool operator()(const std::type_info* a, const std::type_info* b) const
56 return a->before(*b) != 0;
59 template<class T>
60 bool operator()(const T& a, const T& b) const
62 return a < b;
66 class_rep* find_class(LUABIND_TYPE_INFO info) const;
68 private:
70 std::map<LUABIND_TYPE_INFO, class_rep*, cmp> m_classes;
72 // this is a lua reference that points to the lua table
73 // that is to be used as meta table for all C++ class
74 // instances. It is a kind of v-table.
75 int m_cpp_instance_metatable;
77 // this is a lua reference to the metatable to be used
78 // for all classes defined in C++.
79 int m_cpp_class_metatable;
81 // this is a lua reference that points to the lua table
82 // that is to be used as meta table for all lua class
83 // instances. It is a kind of v-table.
84 int m_lua_instance_metatable;
86 // this is a lua reference to the metatable to be used
87 // for all classes defined in lua
88 int m_lua_class_metatable;
90 // this metatable only contains a destructor
91 // for luabind::Detail::free_functions::function_rep
92 int m_lua_function_metatable;
98 #endif // LUABIND_CLASS_REGISTRY_HPP_INCLUDED