scope.hpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. // Copyright (c) 2004 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 NEW_SCOPE_040211_HPP
  20. #define NEW_SCOPE_040211_HPP
  21. #include <luabind/prefix.hpp>
  22. #include <luabind/config.hpp>
  23. #include <luabind/lua_include.hpp>
  24. #include <memory>
  25. namespace luabind {
  26. struct scope;
  27. } // namespace luabind
  28. namespace luabind { namespace detail {
  29. struct LUABIND_API registration
  30. {
  31. registration();
  32. virtual ~registration();
  33. protected:
  34. virtual void register_(lua_State*) const = 0;
  35. private:
  36. friend struct ::luabind::scope;
  37. registration* m_next;
  38. };
  39. }} // namespace luabind::detail
  40. namespace luabind {
  41. struct LUABIND_API scope
  42. {
  43. scope();
  44. explicit scope(std::auto_ptr<detail::registration> reg);
  45. scope(scope const& other_);
  46. ~scope();
  47. scope& operator=(scope const& other_);
  48. scope& operator,(scope s);
  49. void register_(lua_State* L) const;
  50. private:
  51. detail::registration* m_chain;
  52. };
  53. class LUABIND_API namespace_ : public scope
  54. {
  55. public:
  56. explicit namespace_(char const* name);
  57. namespace_& operator[](scope s);
  58. private:
  59. struct registration_;
  60. registration_* m_registration;
  61. };
  62. class LUABIND_API module_
  63. {
  64. public:
  65. module_(lua_State* L_, char const* name);
  66. void operator[](scope s);
  67. private:
  68. lua_State* m_state;
  69. char const* name_;
  70. };
  71. inline module_ module(lua_State* L, char const* name = 0)
  72. {
  73. return module_(L, name);
  74. }
  75. } // namespace luabind
  76. #endif // NEW_SCOPE_040211_HPP