class_registry.hpp 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. // Copyright (c) 2003 Daniel Wallin and Arvid Norberg
  2. // Permission is hereby granted, free of charge, to any person obtaining a
  3. // copy of this software and associated documentation files (the "Software"),
  4. // to deal in the Software without restriction, including without limitation
  5. // the rights to use, copy, modify, merge, publish, distribute, sublicense,
  6. // and/or sell copies of the Software, and to permit persons to whom the
  7. // Software is furnished to do so, subject to the following conditions:
  8. // The above copyright notice and this permission notice shall be included
  9. // in all copies or substantial portions of the Software.
  10. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
  11. // ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
  12. // TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  13. // PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
  14. // SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
  15. // ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  16. // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  17. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
  18. // OR OTHER DEALINGS IN THE SOFTWARE.
  19. #ifndef LUABIND_CLASS_REGISTRY_HPP_INCLUDED
  20. #define LUABIND_CLASS_REGISTRY_HPP_INCLUDED
  21. #include <map>
  22. #include <luabind/config.hpp>
  23. #include <luabind/open.hpp>
  24. #include <luabind/typeid.hpp>
  25. namespace luabind { namespace detail
  26. {
  27. class class_rep;
  28. struct LUABIND_API class_registry
  29. {
  30. class_registry(lua_State* L);
  31. static class_registry* get_registry(lua_State* L);
  32. int cpp_instance() const { return m_instance_metatable; }
  33. int cpp_class() const { return m_cpp_class_metatable; }
  34. int lua_instance() const { return m_instance_metatable; }
  35. int lua_class() const { return m_lua_class_metatable; }
  36. int lua_function() const { return m_lua_function_metatable; }
  37. void add_class(type_id const& info, class_rep* crep);
  38. class_rep* find_class(type_id const& info) const;
  39. std::map<type_id, class_rep*> const& get_classes() const
  40. {
  41. return m_classes;
  42. }
  43. private:
  44. std::map<type_id, class_rep*> m_classes;
  45. // this is a lua reference that points to the lua table
  46. // that is to be used as meta table for all C++ class
  47. // instances. It is a kind of v-table.
  48. int m_instance_metatable;
  49. // this is a lua reference to the metatable to be used
  50. // for all classes defined in C++.
  51. int m_cpp_class_metatable;
  52. // this is a lua reference to the metatable to be used
  53. // for all classes defined in lua
  54. int m_lua_class_metatable;
  55. // this metatable only contains a destructor
  56. // for luabind::Detail::free_functions::function_rep
  57. int m_lua_function_metatable;
  58. };
  59. }}
  60. #endif // LUABIND_CLASS_REGISTRY_HPP_INCLUDED