mirror of
https://github.com/ThePhD/sol2.git
synced 2024-03-22 13:10:44 +08:00
freeze changes
This commit is contained in:
parent
9b47849110
commit
094ace3c7b
|
@ -1,4 +1,4 @@
|
|||
// sol3
|
||||
// sol3
|
||||
|
||||
// The MIT License (MIT)
|
||||
|
||||
|
@ -41,7 +41,12 @@ namespace sol {
|
|||
call_status stats = call_status::yielded;
|
||||
|
||||
void luacall(std::ptrdiff_t argcount, std::ptrdiff_t) {
|
||||
#if SOL_LUA_VERSION >= 504
|
||||
int nresults;
|
||||
stats = static_cast<call_status>(lua_resume(lua_state(), nullptr, static_cast<int>(argcount), &nresults));
|
||||
#else
|
||||
stats = static_cast<call_status>(lua_resume(lua_state(), nullptr, static_cast<int>(argcount)));
|
||||
#endif
|
||||
}
|
||||
|
||||
template <std::size_t... I, typename... Ret>
|
||||
|
@ -84,7 +89,7 @@ namespace sol {
|
|||
basic_coroutine() = default;
|
||||
template <typename T, meta::enable<meta::neg<std::is_same<meta::unqualified_t<T>, basic_coroutine>>, meta::neg<std::is_base_of<proxy_base_tag, meta::unqualified_t<T>>>, meta::neg<std::is_same<base_t, stack_reference>>, meta::neg<std::is_same<lua_nil_t, meta::unqualified_t<T>>>, is_lua_reference<meta::unqualified_t<T>>> = meta::enabler>
|
||||
basic_coroutine(T&& r) noexcept
|
||||
: base_t(std::forward<T>(r)), error_handler(detail::get_default_handler<reference, is_main_threaded<base_t>::value>(r.lua_state())) {
|
||||
: base_t(std::forward<T>(r)), error_handler(detail::get_default_handler<reference, is_main_threaded<base_t>::value>(r.lua_state())) {
|
||||
#if defined(SOL_SAFE_REFERENCES) && SOL_SAFE_REFERENCES
|
||||
if (!is_function<meta::unqualified_t<T>>::value) {
|
||||
auto pp = stack::push_pop(*this);
|
||||
|
@ -98,50 +103,50 @@ namespace sol {
|
|||
basic_coroutine(basic_coroutine&&) = default;
|
||||
basic_coroutine& operator=(basic_coroutine&&) = default;
|
||||
basic_coroutine(const basic_function<base_t>& b)
|
||||
: basic_coroutine(b, detail::get_default_handler<reference, is_main_threaded<base_t>::value>(b.lua_state())) {
|
||||
: basic_coroutine(b, detail::get_default_handler<reference, is_main_threaded<base_t>::value>(b.lua_state())) {
|
||||
}
|
||||
basic_coroutine(basic_function<base_t>&& b)
|
||||
: basic_coroutine(std::move(b), detail::get_default_handler<reference, is_main_threaded<base_t>::value>(b.lua_state())) {
|
||||
: basic_coroutine(std::move(b), detail::get_default_handler<reference, is_main_threaded<base_t>::value>(b.lua_state())) {
|
||||
}
|
||||
basic_coroutine(const basic_function<base_t>& b, handler_t eh)
|
||||
: base_t(b), error_handler(std::move(eh)) {
|
||||
: base_t(b), error_handler(std::move(eh)) {
|
||||
}
|
||||
basic_coroutine(basic_function<base_t>&& b, handler_t eh)
|
||||
: base_t(std::move(b)), error_handler(std::move(eh)) {
|
||||
: base_t(std::move(b)), error_handler(std::move(eh)) {
|
||||
}
|
||||
basic_coroutine(const stack_reference& r)
|
||||
: basic_coroutine(r.lua_state(), r.stack_index(), detail::get_default_handler<reference, is_main_threaded<base_t>::value>(r.lua_state())) {
|
||||
: basic_coroutine(r.lua_state(), r.stack_index(), detail::get_default_handler<reference, is_main_threaded<base_t>::value>(r.lua_state())) {
|
||||
}
|
||||
basic_coroutine(stack_reference&& r)
|
||||
: basic_coroutine(r.lua_state(), r.stack_index(), detail::get_default_handler<reference, is_main_threaded<base_t>::value>(r.lua_state())) {
|
||||
: basic_coroutine(r.lua_state(), r.stack_index(), detail::get_default_handler<reference, is_main_threaded<base_t>::value>(r.lua_state())) {
|
||||
}
|
||||
basic_coroutine(const stack_reference& r, handler_t eh)
|
||||
: basic_coroutine(r.lua_state(), r.stack_index(), std::move(eh)) {
|
||||
: basic_coroutine(r.lua_state(), r.stack_index(), std::move(eh)) {
|
||||
}
|
||||
basic_coroutine(stack_reference&& r, handler_t eh)
|
||||
: basic_coroutine(r.lua_state(), r.stack_index(), std::move(eh)) {
|
||||
: basic_coroutine(r.lua_state(), r.stack_index(), std::move(eh)) {
|
||||
}
|
||||
|
||||
template <typename Super>
|
||||
basic_coroutine(const proxy_base<Super>& p)
|
||||
: basic_coroutine(p, detail::get_default_handler<reference, is_main_threaded<base_t>::value>(p.lua_state())) {
|
||||
: basic_coroutine(p, detail::get_default_handler<reference, is_main_threaded<base_t>::value>(p.lua_state())) {
|
||||
}
|
||||
template <typename Super>
|
||||
basic_coroutine(proxy_base<Super>&& p)
|
||||
: basic_coroutine(std::move(p), detail::get_default_handler<reference, is_main_threaded<base_t>::value>(p.lua_state())) {
|
||||
: basic_coroutine(std::move(p), detail::get_default_handler<reference, is_main_threaded<base_t>::value>(p.lua_state())) {
|
||||
}
|
||||
template <typename Proxy, typename Handler, meta::enable<std::is_base_of<proxy_base_tag, meta::unqualified_t<Proxy>>, meta::neg<is_lua_index<meta::unqualified_t<Handler>>>> = meta::enabler>
|
||||
basic_coroutine(Proxy&& p, Handler&& eh)
|
||||
: basic_coroutine(detail::force_cast<base_t>(p), std::forward<Handler>(eh)) {
|
||||
: basic_coroutine(detail::force_cast<base_t>(p), std::forward<Handler>(eh)) {
|
||||
}
|
||||
|
||||
template <typename T, meta::enable<is_lua_reference<meta::unqualified_t<T>>> = meta::enabler>
|
||||
basic_coroutine(lua_State* L, T&& r)
|
||||
: basic_coroutine(L, std::forward<T>(r), detail::get_default_handler<reference, is_main_threaded<base_t>::value>(L)) {
|
||||
: basic_coroutine(L, std::forward<T>(r), detail::get_default_handler<reference, is_main_threaded<base_t>::value>(L)) {
|
||||
}
|
||||
template <typename T, meta::enable<is_lua_reference<meta::unqualified_t<T>>> = meta::enabler>
|
||||
basic_coroutine(lua_State* L, T&& r, handler_t eh)
|
||||
: base_t(L, std::forward<T>(r)), error_handler(std::move(eh)) {
|
||||
: base_t(L, std::forward<T>(r)), error_handler(std::move(eh)) {
|
||||
#if defined(SOL_SAFE_REFERENCES) && SOL_SAFE_REFERENCES
|
||||
auto pp = stack::push_pop(*this);
|
||||
constructor_handler handler{};
|
||||
|
@ -150,44 +155,44 @@ namespace sol {
|
|||
}
|
||||
|
||||
basic_coroutine(lua_nil_t n)
|
||||
: base_t(n), error_handler(n) {
|
||||
: base_t(n), error_handler(n) {
|
||||
}
|
||||
|
||||
basic_coroutine(lua_State* L, int index = -1)
|
||||
: basic_coroutine(L, index, detail::get_default_handler<reference, is_main_threaded<base_t>::value>(L)) {
|
||||
: basic_coroutine(L, index, detail::get_default_handler<reference, is_main_threaded<base_t>::value>(L)) {
|
||||
}
|
||||
basic_coroutine(lua_State* L, int index, handler_t eh)
|
||||
: base_t(L, index), error_handler(std::move(eh)) {
|
||||
: base_t(L, index), error_handler(std::move(eh)) {
|
||||
#ifdef SOL_SAFE_REFERENCES
|
||||
constructor_handler handler{};
|
||||
stack::check<basic_coroutine>(L, index, handler);
|
||||
#endif // Safety
|
||||
}
|
||||
basic_coroutine(lua_State* L, absolute_index index)
|
||||
: basic_coroutine(L, index, detail::get_default_handler<reference, is_main_threaded<base_t>::value>(L)) {
|
||||
: basic_coroutine(L, index, detail::get_default_handler<reference, is_main_threaded<base_t>::value>(L)) {
|
||||
}
|
||||
basic_coroutine(lua_State* L, absolute_index index, handler_t eh)
|
||||
: base_t(L, index), error_handler(std::move(eh)) {
|
||||
: base_t(L, index), error_handler(std::move(eh)) {
|
||||
#if defined(SOL_SAFE_REFERENCES) && SOL_SAFE_REFERENCES
|
||||
constructor_handler handler{};
|
||||
stack::check<basic_coroutine>(L, index, handler);
|
||||
#endif // Safety
|
||||
}
|
||||
basic_coroutine(lua_State* L, raw_index index)
|
||||
: basic_coroutine(L, index, detail::get_default_handler<reference, is_main_threaded<base_t>::value>(L)) {
|
||||
: basic_coroutine(L, index, detail::get_default_handler<reference, is_main_threaded<base_t>::value>(L)) {
|
||||
}
|
||||
basic_coroutine(lua_State* L, raw_index index, handler_t eh)
|
||||
: base_t(L, index), error_handler(std::move(eh)) {
|
||||
: base_t(L, index), error_handler(std::move(eh)) {
|
||||
#if defined(SOL_SAFE_REFERENCES) && SOL_SAFE_REFERENCES
|
||||
constructor_handler handler{};
|
||||
stack::check<basic_coroutine>(L, index, handler);
|
||||
#endif // Safety
|
||||
}
|
||||
basic_coroutine(lua_State* L, ref_index index)
|
||||
: basic_coroutine(L, index, detail::get_default_handler<reference, is_main_threaded<base_t>::value>(L)) {
|
||||
: basic_coroutine(L, index, detail::get_default_handler<reference, is_main_threaded<base_t>::value>(L)) {
|
||||
}
|
||||
basic_coroutine(lua_State* L, ref_index index, handler_t eh)
|
||||
: base_t(L, index), error_handler(std::move(eh)) {
|
||||
: base_t(L, index), error_handler(std::move(eh)) {
|
||||
#if defined(SOL_SAFE_REFERENCES) && SOL_SAFE_REFERENCES
|
||||
auto pp = stack::push_pop(*this);
|
||||
constructor_handler handler{};
|
||||
|
|
|
@ -502,9 +502,7 @@ namespace sol {
|
|||
return &usertype_alloc_destruct<T>;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return &cannot_destruct<T>;
|
||||
}
|
||||
return &cannot_destruct<T>;
|
||||
}
|
||||
|
||||
struct no_comp {
|
||||
|
|
|
@ -131,7 +131,9 @@ namespace sol {
|
|||
int index = 0;
|
||||
detail::indexed_insert insert_fx(l, index);
|
||||
detail::insert_default_registrations<P>(insert_fx, detail::property_always_true);
|
||||
l[index] = luaL_Reg{ to_string(meta_function::garbage_collect).c_str(), detail::make_destructor<P>() };
|
||||
if constexpr (!std::is_pointer_v<T>) {
|
||||
l[index] = luaL_Reg{ to_string(meta_function::garbage_collect).c_str(), detail::make_destructor<P>() };
|
||||
}
|
||||
luaL_setfuncs(L, l, 0);
|
||||
|
||||
// __type table
|
||||
|
|
|
@ -453,16 +453,17 @@ namespace u_detail {
|
|||
this->storage.push_back(std::move(p_binding));
|
||||
|
||||
std::string s = u_detail::make_string(std::forward<Key>(key));
|
||||
bool is_index = is_var_bind::value || (s == to_string(meta_function::index));
|
||||
bool is_new_index = is_var_bind::value || (s == to_string(meta_function::new_index));
|
||||
bool is_index = (s == to_string(meta_function::index));
|
||||
bool is_new_index = (s == to_string(meta_function::new_index));
|
||||
bool no_use_named = s == to_string(meta_function::call);
|
||||
bool poison_indexing = is_var_bind::value || is_index || is_new_index;
|
||||
index_call_storage ics;
|
||||
ics.binding_data = b.data();
|
||||
ics.index = &b.index_call_with_<true, is_var_bind::value>;
|
||||
ics.new_index = &b.index_call_with_<false, is_var_bind::value>;
|
||||
ics.index = is_index ? &b.call_with_<true, is_var_bind::value> : &b.index_call_with_<true, is_var_bind::value>;
|
||||
ics.new_index = is_new_index ? &b.call_with_<false, is_var_bind::value> : &b.index_call_with_<false, is_var_bind::value>;
|
||||
// need to swap everything to use fast indexing here
|
||||
auto fet = [&](lua_State* L, submetatable submetatable_type, reference& fast_index_table) {
|
||||
if (submetatable_type == submetatable::named && (no_use_named || is_index || is_new_index)) {
|
||||
if (submetatable_type == submetatable::named && (no_use_named || poison_indexing)) {
|
||||
// do not override __call or
|
||||
// other specific meta functions on named metatable:
|
||||
// we need that for call construction
|
||||
|
@ -477,7 +478,7 @@ namespace u_detail {
|
|||
else {
|
||||
stack::set_field<false, true>(L, s, make_closure(&b.call<false, is_var_bind::value>, nullptr, ics.binding_data), t.stack_index());
|
||||
}
|
||||
if (is_index || is_new_index) {
|
||||
if (poison_indexing) {
|
||||
change_indexing<T>(L, submetatable_type, t);
|
||||
}
|
||||
t.pop();
|
||||
|
@ -781,7 +782,7 @@ namespace u_detail {
|
|||
stack::set_field(L, detail::base_class_cast_key(), (void*)&detail::inheritance<T>::type_cast, t.stack_index());
|
||||
}
|
||||
|
||||
auto prop_fx = properties_enrollment_allowed(storage.properties, enrollments);
|
||||
auto prop_fx = detail::properties_enrollment_allowed(storage.properties, enrollments);
|
||||
auto insert_fx = [&](meta_function mf, lua_CFunction reg) {
|
||||
stack::set_field(L, mf, reg, t.stack_index());
|
||||
storage.properties[static_cast<int>(mf)] = true;
|
||||
|
|
|
@ -372,15 +372,6 @@ TEST_CASE("operators/container-like", "test that generic begin/end and iterator
|
|||
REQUIRE(i == 10);
|
||||
}
|
||||
}
|
||||
SECTION("simple") {
|
||||
lua.new_simple_usertype<container>("container");
|
||||
{
|
||||
lua.safe_script("obj = container.new()");
|
||||
lua.safe_script("i = 0 for k, v in pairs(obj) do i = i + 1 assert(k == v) end");
|
||||
std::size_t i = lua["i"];
|
||||
REQUIRE(i == 10);
|
||||
}
|
||||
}
|
||||
#else
|
||||
SUCCEED("");
|
||||
#endif
|
||||
|
|
|
@ -41,6 +41,25 @@ bool func_opt_ret_bool(sol::optional<int> i) {
|
|||
return true;
|
||||
}
|
||||
|
||||
struct base1 {
|
||||
int a1 = 250;
|
||||
};
|
||||
|
||||
struct base2 {
|
||||
int a2 = 500;
|
||||
};
|
||||
|
||||
struct simple : base1 {
|
||||
};
|
||||
|
||||
struct complex : base1, base2 {
|
||||
};
|
||||
|
||||
SOL_BASE_CLASSES(complex, base1, base2);
|
||||
SOL_BASE_CLASSES(simple, base1);
|
||||
SOL_DERIVED_CLASSES(base1, simple, complex);
|
||||
SOL_DERIVED_CLASSES(base2, complex);
|
||||
|
||||
TEST_CASE("table/traversal", "ensure that we can chain requests and tunnel down into a value if we desire") {
|
||||
|
||||
sol::state lua;
|
||||
|
@ -409,11 +428,12 @@ TEST_CASE("feature/indexing overrides", "make sure index functions can be overri
|
|||
sol::usertype<DynamicObject> utdo = lua.new_usertype<DynamicObject>("DynamicObject");
|
||||
utdo["props"] = sol::property(&DynamicObject::get_dynamic_props);
|
||||
|
||||
lua.safe_script(R"__(
|
||||
auto result = lua.safe_script(R"__(
|
||||
obj = DynamicObject:new()
|
||||
obj.props.name = 'test name'
|
||||
print('name = ' .. obj.props.name)
|
||||
)__");
|
||||
)__", sol::script_pass_on_error);
|
||||
REQUIRE(result.valid());
|
||||
|
||||
std::string name = lua["obj"]["props"]["name"];
|
||||
REQUIRE(name == "test name");
|
||||
|
@ -459,20 +479,6 @@ TEST_CASE("features/indexing numbers", "make sure indexing functions can be over
|
|||
}
|
||||
|
||||
TEST_CASE("features/multiple inheritance", "Ensure that multiple inheritance works as advertised") {
|
||||
struct base1 {
|
||||
int a1 = 250;
|
||||
};
|
||||
|
||||
struct base2 {
|
||||
int a2 = 500;
|
||||
};
|
||||
|
||||
struct simple : base1 {
|
||||
};
|
||||
|
||||
struct complex : base1, base2 {
|
||||
};
|
||||
|
||||
sol::state lua;
|
||||
lua.open_libraries(sol::lib::base);
|
||||
lua.new_usertype<base1>("base1",
|
||||
|
@ -596,14 +602,14 @@ TEST_CASE("compilation/const regression", "make sure constness in tables is resp
|
|||
struct State {
|
||||
public:
|
||||
State() {
|
||||
this->state_.registry()["state"] = this;
|
||||
this->state_.globals()["state"] = this;
|
||||
}
|
||||
|
||||
sol::state state_;
|
||||
};
|
||||
|
||||
State state;
|
||||
State* s = state.state_.registry()["state"];
|
||||
State* s = state.state_.globals()["state"];
|
||||
REQUIRE(s == &state);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user