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 <luabind/config.hpp>
28 #include <luabind/open.hpp>
29 #include <luabind/typeid.hpp>
30 
31 #include <map>
32 
33 namespace luabind { namespace detail
34 {
35     class class_rep;
36 
37     extern char classes_tag; // Not used in headers, thus no LUABIND_API.
38 
39     struct LUABIND_API class_registry
40     {
41         class_registry(lua_State* L);
42 
43         static class_registry* get_registry(lua_State* L);
44 
cpp_instanceluabind::detail::class_registry45         int cpp_instance() const { return m_instance_metatable; }
cpp_classluabind::detail::class_registry46         int cpp_class() const { return m_cpp_class_metatable; }
47 
lua_instanceluabind::detail::class_registry48         int lua_instance() const { return m_instance_metatable; }
lua_classluabind::detail::class_registry49         int lua_class() const { return m_lua_class_metatable; }
lua_functionluabind::detail::class_registry50         int lua_function() const { return m_lua_function_metatable; }
51 
52         void add_class(type_id const& info, class_rep* crep);
53 
54         class_rep* find_class(type_id const& info) const;
55 
get_classesluabind::detail::class_registry56         std::map<type_id, class_rep*> const& get_classes() const
57         {
58             return m_classes;
59         }
60 
61     private:
62 
63         std::map<type_id, class_rep*> m_classes;
64 
65         // this is a lua reference that points to the lua table
66         // that is to be used as meta table for all C++ class
67         // instances. It is a kind of v-table.
68         int m_instance_metatable;
69 
70         // this is a lua reference to the metatable to be used
71         // for all classes defined in C++.
72         int m_cpp_class_metatable;
73 
74         // this is a lua reference to the metatable to be used
75         // for all classes defined in lua
76         int m_lua_class_metatable;
77 
78         // this metatable only contains a destructor
79         // for luabind::Detail::free_functions::function_rep
80         int m_lua_function_metatable;
81 
82     };
83 
84 }}
85 
86 #endif // LUABIND_CLASS_REGISTRY_HPP_INCLUDED
87