state.hpp 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // sol2
  2. // The MIT License (MIT)
  3. // Copyright (c) 2013-2022 Rapptz, ThePhD and contributors
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy of
  5. // this software and associated documentation files (the "Software"), to deal in
  6. // the Software without restriction, including without limitation the rights to
  7. // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  8. // the Software, and to permit persons to whom the Software is furnished to do so,
  9. // subject to the following conditions:
  10. // The above copyright notice and this permission notice shall be included in all
  11. // copies or substantial portions of the Software.
  12. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  13. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  14. // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  15. // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  16. // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  17. // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  18. #ifndef SOL_STATE_HPP
  19. #define SOL_STATE_HPP
  20. #include <sol/state_view.hpp>
  21. #include <sol/thread.hpp>
  22. namespace fastweb
  23. {
  24. class app;
  25. }
  26. namespace sol {
  27. class state : private std::unique_ptr<lua_State, detail::state_deleter>, public state_view {
  28. private:
  29. typedef std::unique_ptr<lua_State, detail::state_deleter> unique_base;
  30. public:
  31. state(lua_CFunction panic = default_at_panic) : unique_base(luaL_newstate()), state_view(unique_base::get()) {
  32. set_default_state(unique_base::get(), panic);
  33. }
  34. state(lua_CFunction panic, lua_Alloc alfunc, void* alpointer = nullptr)
  35. : unique_base(lua_newstate(alfunc, alpointer)), state_view(unique_base::get()) {
  36. set_default_state(unique_base::get(), panic);
  37. }
  38. state(const state&) = delete;
  39. state(state&&) = default;
  40. state& operator=(const state&) = delete;
  41. state& operator=(state&& that) {
  42. state_view::operator=(std::move(that));
  43. unique_base::operator=(std::move(that));
  44. return *this;
  45. }
  46. using state_view::get;
  47. ~state() {
  48. }
  49. };
  50. } // namespace sol
  51. #endif // SOL_STATE_HPP