mirror of
https://github.com/ThePhD/sol2.git
synced 2024-03-22 13:10:44 +08:00
update single and add unused parameter checks to thread
This commit is contained in:
parent
e201f85a4c
commit
0325e27454
|
@ -20,8 +20,8 @@
|
|||
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
// This file was generated with a script.
|
||||
// Generated 2017-09-11 20:41:41.805495 UTC
|
||||
// This header was generated with sol v2.18.2 (revision 074b9ae)
|
||||
// Generated 2017-09-12 23:51:14.830850 UTC
|
||||
// This header was generated with sol v2.18.2 (revision e201f85)
|
||||
// https://github.com/ThePhD/sol2
|
||||
|
||||
#ifndef SOL_SINGLE_INCLUDE_HPP
|
||||
|
@ -5797,10 +5797,10 @@ namespace sol {
|
|||
deref();
|
||||
}
|
||||
|
||||
reference(reference&& o) noexcept {
|
||||
luastate = o.luastate;
|
||||
ref = o.ref;
|
||||
reference(const reference& o) noexcept : luastate(o.luastate), ref(o.copy()) {
|
||||
}
|
||||
|
||||
reference(reference&& o) noexcept : luastate(o.luastate), ref(o.ref) {
|
||||
o.luastate = nullptr;
|
||||
o.ref = LUA_NOREF;
|
||||
}
|
||||
|
@ -5809,8 +5809,24 @@ namespace sol {
|
|||
if (valid()) {
|
||||
deref();
|
||||
}
|
||||
if (lua_state() != o.lua_state() && lua_state() != nullptr) {
|
||||
// different state (different threads???)
|
||||
if (o.lua_state() != nullptr) {
|
||||
// both are valid but different?
|
||||
o.push(lua_state());
|
||||
ref = luaL_ref(lua_state(), LUA_REGISTRYINDEX);
|
||||
return *this;
|
||||
}
|
||||
else {
|
||||
luastate = o.luastate;
|
||||
ref = o.ref;
|
||||
}
|
||||
}
|
||||
else {
|
||||
// same state, or this state is nullptr
|
||||
luastate = o.luastate;
|
||||
ref = o.ref;
|
||||
}
|
||||
|
||||
o.luastate = nullptr;
|
||||
o.ref = LUA_NOREF;
|
||||
|
@ -5818,14 +5834,24 @@ namespace sol {
|
|||
return *this;
|
||||
}
|
||||
|
||||
reference(const reference& o) noexcept {
|
||||
luastate = o.luastate;
|
||||
ref = o.copy();
|
||||
}
|
||||
|
||||
reference& operator=(const reference& o) noexcept {
|
||||
luastate = o.luastate;
|
||||
if (valid()) {
|
||||
deref();
|
||||
}
|
||||
if (lua_state() != o.lua_state() && lua_state() != nullptr) {
|
||||
// different state (different threads???)
|
||||
if (o.lua_state() != nullptr) {
|
||||
// both are valid but different?
|
||||
o.push(lua_state());
|
||||
ref = luaL_ref(lua_state(), LUA_REGISTRYINDEX);
|
||||
}
|
||||
else {
|
||||
luastate = o.luastate;
|
||||
ref = o.ref;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
luastate = o.luastate;
|
||||
ref = o.copy();
|
||||
return *this;
|
||||
}
|
||||
|
@ -6090,6 +6116,11 @@ namespace sol {
|
|||
void reserve(std::basic_string<T, Tr, Al>& arr, std::size_t hint) {
|
||||
arr.reserve(hint);
|
||||
}
|
||||
|
||||
inline const char(&default_main_thread_name())[9]{
|
||||
static const char name[9] = "sol.\xF0\x9F\x93\x8C";
|
||||
return name;
|
||||
}
|
||||
} // detail
|
||||
|
||||
namespace stack {
|
||||
|
@ -9421,6 +9452,9 @@ namespace sol {
|
|||
|
||||
inline void luajit_exception_handler(lua_State* L, int(*handler)(lua_State*, lua_CFunction) = detail::c_trampoline) {
|
||||
#ifdef SOL_LUAJIT
|
||||
if (L == nullptr) {
|
||||
return;
|
||||
}
|
||||
lua_pushlightuserdata(L, (void*)handler);
|
||||
auto pn = pop_n(L, 1);
|
||||
luaJIT_setmode(L, -1, LUAJIT_MODE_WRAPCFUNC | LUAJIT_MODE_ON);
|
||||
|
@ -9432,6 +9466,9 @@ namespace sol {
|
|||
|
||||
inline void luajit_exception_off(lua_State* L) {
|
||||
#ifdef SOL_LUAJIT
|
||||
if (L == nullptr) {
|
||||
return;
|
||||
}
|
||||
luaJIT_setmode(L, -1, LUAJIT_MODE_WRAPCFUNC | LUAJIT_MODE_OFF);
|
||||
#else
|
||||
(void)L;
|
||||
|
@ -11973,8 +12010,8 @@ namespace sol {
|
|||
|
||||
namespace sol {
|
||||
namespace detail {
|
||||
inline const char (&default_handler_name())[11] {
|
||||
static const char name[11] = "sol.\xF0\x9F\x94\xA9";
|
||||
inline const char (&default_handler_name())[9] {
|
||||
static const char name[9] = "sol.\xF0\x9F\x94\xA9";
|
||||
return name;
|
||||
}
|
||||
|
||||
|
@ -17992,83 +18029,6 @@ namespace sol {
|
|||
|
||||
// end of sol/state_view.hpp
|
||||
|
||||
namespace sol {
|
||||
|
||||
namespace detail {
|
||||
inline int default_at_panic(lua_State* L) {
|
||||
#ifdef SOL_NO_EXCEPTIONS
|
||||
(void)L;
|
||||
return -1;
|
||||
#else
|
||||
size_t messagesize;
|
||||
const char* message = lua_tolstring(L, -1, &messagesize);
|
||||
if (message) {
|
||||
std::string err(message, messagesize);
|
||||
lua_settop(L, 0);
|
||||
throw error(err);
|
||||
}
|
||||
lua_settop(L, 0);
|
||||
throw error(std::string("An unexpected error occurred and forced the lua state to call atpanic"));
|
||||
#endif
|
||||
}
|
||||
|
||||
inline int default_traceback_error_handler(lua_State*L) {
|
||||
using namespace sol;
|
||||
std::string msg = "An unknown error has triggered the default error handler";
|
||||
optional<string_view> maybetopmsg = stack::check_get<string_view>(L, 1);
|
||||
if (maybetopmsg) {
|
||||
const string_view& topmsg = maybetopmsg.value();
|
||||
msg.assign(topmsg.data(), topmsg.size());
|
||||
}
|
||||
luaL_traceback(L, L, msg.c_str(), 1);
|
||||
optional<string_view> maybetraceback = stack::check_get<string_view>(L, -1);
|
||||
if (maybetraceback) {
|
||||
const string_view& traceback = maybetraceback.value();
|
||||
msg.assign(traceback.data(), traceback.size());
|
||||
}
|
||||
return stack::push(L, msg);
|
||||
}
|
||||
} // detail
|
||||
|
||||
class state : private std::unique_ptr<lua_State, void(*)(lua_State*)>, public state_view {
|
||||
private:
|
||||
typedef std::unique_ptr<lua_State, void(*)(lua_State*)> unique_base;
|
||||
public:
|
||||
state(lua_CFunction panic = detail::default_at_panic) : unique_base(luaL_newstate(), lua_close),
|
||||
state_view(unique_base::get()) {
|
||||
set_panic(panic);
|
||||
lua_CFunction f = c_call<decltype(&detail::default_traceback_error_handler), &detail::default_traceback_error_handler>;
|
||||
sol::protected_function::set_default_handler(sol::object(lua_state(), in_place, f));
|
||||
stack::luajit_exception_handler(unique_base::get());
|
||||
}
|
||||
|
||||
state(lua_CFunction panic, lua_Alloc alfunc, void* alpointer = nullptr) : unique_base(lua_newstate(alfunc, alpointer), lua_close),
|
||||
state_view(unique_base::get()) {
|
||||
set_panic(panic);
|
||||
lua_CFunction f = c_call<decltype(&detail::default_traceback_error_handler), &detail::default_traceback_error_handler>;
|
||||
sol::protected_function::set_default_handler(sol::object(lua_state(), in_place, f));
|
||||
stack::luajit_exception_handler(unique_base::get());
|
||||
}
|
||||
|
||||
state(const state&) = delete;
|
||||
state(state&&) = default;
|
||||
state& operator=(const state&) = delete;
|
||||
state& operator=(state&& that) {
|
||||
state_view::operator=(std::move(that));
|
||||
unique_base::operator=(std::move(that));
|
||||
return *this;
|
||||
}
|
||||
|
||||
using state_view::get;
|
||||
|
||||
~state() {}
|
||||
};
|
||||
} // sol
|
||||
|
||||
// end of sol/state.hpp
|
||||
|
||||
// beginning of sol/coroutine.hpp
|
||||
|
||||
// beginning of sol/thread.hpp
|
||||
|
||||
namespace sol {
|
||||
|
@ -18083,7 +18043,6 @@ namespace sol {
|
|||
};
|
||||
|
||||
namespace stack {
|
||||
|
||||
template <>
|
||||
struct pusher<lua_thread_state> {
|
||||
int push(lua_State*, lua_thread_state lts) {
|
||||
|
@ -18115,19 +18074,38 @@ namespace sol {
|
|||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
inline void register_main_thread(lua_State* L) {
|
||||
#if SOL_LUA_VERSION < 502
|
||||
inline lua_State* main_thread(lua_State*, lua_State* backup_if_unsupported = nullptr) {
|
||||
return backup_if_unsupported;
|
||||
if (L == nullptr) {
|
||||
lua_pushnil(L);
|
||||
lua_setglobal(L, detail::default_main_thread_name());
|
||||
return;
|
||||
}
|
||||
lua_pushthread(L);
|
||||
lua_setglobal(L, detail::default_main_thread_name());
|
||||
#else
|
||||
inline lua_State* main_thread(lua_State* L, lua_State* = nullptr) {
|
||||
(void)L;
|
||||
#endif
|
||||
}
|
||||
} // stack
|
||||
|
||||
inline lua_State* main_thread(lua_State* L, lua_State* backup_if_unsupported = nullptr) {
|
||||
#if SOL_LUA_VERSION < 502
|
||||
if (L == nullptr)
|
||||
return backup_if_unsupported;
|
||||
lua_getglobal(L, detail::default_main_thread_name());
|
||||
auto pp = stack::pop_n(L, 1);
|
||||
if (type_of(L, -1) == type::thread) {
|
||||
return lua_tothread(L, -1);
|
||||
}
|
||||
return backup_if_unsupported;
|
||||
#else
|
||||
(void)backup_if_unsupported;
|
||||
lua_rawgeti(L, LUA_REGISTRYINDEX, LUA_RIDX_MAINTHREAD);
|
||||
lua_thread_state s = stack::pop<lua_thread_state>(L);
|
||||
return s.L;
|
||||
}
|
||||
#endif // Lua 5.2+ has the main thread getter
|
||||
}
|
||||
|
||||
class thread : public reference {
|
||||
public:
|
||||
|
@ -18203,6 +18181,85 @@ namespace sol {
|
|||
|
||||
// end of sol/thread.hpp
|
||||
|
||||
namespace sol {
|
||||
|
||||
namespace detail {
|
||||
inline int default_at_panic(lua_State* L) {
|
||||
#ifdef SOL_NO_EXCEPTIONS
|
||||
(void)L;
|
||||
return -1;
|
||||
#else
|
||||
size_t messagesize;
|
||||
const char* message = lua_tolstring(L, -1, &messagesize);
|
||||
if (message) {
|
||||
std::string err(message, messagesize);
|
||||
lua_settop(L, 0);
|
||||
throw error(err);
|
||||
}
|
||||
lua_settop(L, 0);
|
||||
throw error(std::string("An unexpected error occurred and forced the lua state to call atpanic"));
|
||||
#endif
|
||||
}
|
||||
|
||||
inline int default_traceback_error_handler(lua_State*L) {
|
||||
using namespace sol;
|
||||
std::string msg = "An unknown error has triggered the default error handler";
|
||||
optional<string_view> maybetopmsg = stack::check_get<string_view>(L, 1);
|
||||
if (maybetopmsg) {
|
||||
const string_view& topmsg = maybetopmsg.value();
|
||||
msg.assign(topmsg.data(), topmsg.size());
|
||||
}
|
||||
luaL_traceback(L, L, msg.c_str(), 1);
|
||||
optional<string_view> maybetraceback = stack::check_get<string_view>(L, -1);
|
||||
if (maybetraceback) {
|
||||
const string_view& traceback = maybetraceback.value();
|
||||
msg.assign(traceback.data(), traceback.size());
|
||||
}
|
||||
return stack::push(L, msg);
|
||||
}
|
||||
} // detail
|
||||
|
||||
class state : private std::unique_ptr<lua_State, void(*)(lua_State*)>, public state_view {
|
||||
private:
|
||||
typedef std::unique_ptr<lua_State, void(*)(lua_State*)> unique_base;
|
||||
public:
|
||||
state(lua_CFunction panic = detail::default_at_panic) : unique_base(luaL_newstate(), lua_close),
|
||||
state_view(unique_base::get()) {
|
||||
set_panic(panic);
|
||||
lua_CFunction f = c_call<decltype(&detail::default_traceback_error_handler), &detail::default_traceback_error_handler>;
|
||||
protected_function::set_default_handler(sol::object(lua_state(), in_place, f));
|
||||
stack::register_main_thread(unique_base::get());
|
||||
stack::luajit_exception_handler(unique_base::get());
|
||||
}
|
||||
|
||||
state(lua_CFunction panic, lua_Alloc alfunc, void* alpointer = nullptr) : unique_base(lua_newstate(alfunc, alpointer), lua_close),
|
||||
state_view(unique_base::get()) {
|
||||
set_panic(panic);
|
||||
lua_CFunction f = c_call<decltype(&detail::default_traceback_error_handler), &detail::default_traceback_error_handler>;
|
||||
protected_function::set_default_handler(sol::object(lua_state(), in_place, f));
|
||||
stack::register_main_thread(unique_base::get());
|
||||
stack::luajit_exception_handler(unique_base::get());
|
||||
}
|
||||
|
||||
state(const state&) = delete;
|
||||
state(state&&) = default;
|
||||
state& operator=(const state&) = delete;
|
||||
state& operator=(state&& that) {
|
||||
state_view::operator=(std::move(that));
|
||||
unique_base::operator=(std::move(that));
|
||||
return *this;
|
||||
}
|
||||
|
||||
using state_view::get;
|
||||
|
||||
~state() {}
|
||||
};
|
||||
} // sol
|
||||
|
||||
// end of sol/state.hpp
|
||||
|
||||
// beginning of sol/coroutine.hpp
|
||||
|
||||
namespace sol {
|
||||
class coroutine : public reference {
|
||||
private:
|
||||
|
|
|
@ -77,12 +77,14 @@ namespace sol {
|
|||
}
|
||||
lua_pushthread(L);
|
||||
lua_setglobal(L, detail::default_main_thread_name());
|
||||
#else
|
||||
(void)L;
|
||||
#endif
|
||||
}
|
||||
} // stack
|
||||
|
||||
#if SOL_LUA_VERSION < 502
|
||||
inline lua_State* main_thread(lua_State* L, lua_State* backup_if_unsupported = nullptr) {
|
||||
#if SOL_LUA_VERSION < 502
|
||||
if (L == nullptr)
|
||||
return backup_if_unsupported;
|
||||
lua_getglobal(L, detail::default_main_thread_name());
|
||||
|
@ -91,14 +93,13 @@ namespace sol {
|
|||
return lua_tothread(L, -1);
|
||||
}
|
||||
return backup_if_unsupported;
|
||||
}
|
||||
#else
|
||||
inline lua_State* main_thread(lua_State* L, lua_State* = nullptr) {
|
||||
(void)backup_if_unsupported;
|
||||
lua_rawgeti(L, LUA_REGISTRYINDEX, LUA_RIDX_MAINTHREAD);
|
||||
lua_thread_state s = stack::pop<lua_thread_state>(L);
|
||||
return s.L;
|
||||
}
|
||||
#endif // Lua 5.2+ has the main thread getter
|
||||
}
|
||||
|
||||
class thread : public reference {
|
||||
public:
|
||||
|
|
Loading…
Reference in New Issue
Block a user