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