1 // Copyright (c) 2003 Daniel Wallin and Arvid Norberg
2 
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:
9 
10 // The above copyright notice and this permission notice shall be included
11 // in all copies or substantial portions of the Software.
12 
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.
22 
23 
24 #ifndef LUABIND_CLASS_REGISTRY_HPP_INCLUDED
25 #define LUABIND_CLASS_REGISTRY_HPP_INCLUDED
26 
27 #include <map>
28 
29 #include <luabind/config.hpp>
30 #include <luabind/open.hpp>
31 #include <luabind/typeid.hpp>
32 
33 namespace luabind { namespace detail
34 {
35 	class class_rep;
36 
37 	struct LUABIND_API class_registry
38 	{
39 		class_registry(lua_State* L);
40 
41 		static class_registry* get_registry(lua_State* L);
42 
cpp_instanceluabind::detail::class_registry43 		int cpp_instance() const { return m_instance_metatable; }
cpp_classluabind::detail::class_registry44 		int cpp_class() const { return m_cpp_class_metatable; }
45 
lua_instanceluabind::detail::class_registry46 		int lua_instance() const { return m_instance_metatable; }
lua_classluabind::detail::class_registry47 		int lua_class() const { return m_lua_class_metatable; }
lua_functionluabind::detail::class_registry48 		int lua_function() const { return m_lua_function_metatable; }
49 
50 		void add_class(type_id const& info, class_rep* crep);
51 
52 		class_rep* find_class(type_id const& info) const;
53 
get_classesluabind::detail::class_registry54         std::map<type_id, class_rep*> const& get_classes() const
55         {
56             return m_classes;
57         }
58 
59 	private:
60 
61 		std::map<type_id, class_rep*> m_classes;
62 
63 		// this is a lua reference that points to the lua table
64 		// that is to be used as meta table for all C++ class
65 		// instances. It is a kind of v-table.
66 		int m_instance_metatable;
67 
68 		// this is a lua reference to the metatable to be used
69 		// for all classes defined in C++.
70 		int m_cpp_class_metatable;
71 
72 		// this is a lua reference to the metatable to be used
73 		// for all classes defined in lua
74 		int m_lua_class_metatable;
75 
76 		// this metatable only contains a destructor
77 		// for luabind::Detail::free_functions::function_rep
78 		int m_lua_function_metatable;
79 
80 	};
81 
82 }}
83 
84 #endif // LUABIND_CLASS_REGISTRY_HPP_INCLUDED
85 
86