From 094ace3c7b3e14888162adaa7b65cfae17ab5346 Mon Sep 17 00:00:00 2001 From: ThePhD Date: Tue, 20 Nov 2018 11:59:36 -0500 Subject: [PATCH] freeze changes --- include/sol/coroutine.hpp | 53 +++++++++++++++++--------------- include/sol/stack_core.hpp | 4 +-- include/sol/usertype_core.hpp | 4 ++- include/sol/usertype_storage.hpp | 15 ++++----- tests/test_operators.cpp | 9 ------ tests/tests.cpp | 42 ++++++++++++++----------- 6 files changed, 65 insertions(+), 62 deletions(-) diff --git a/include/sol/coroutine.hpp b/include/sol/coroutine.hpp index b2105d7e..ff05ab66 100644 --- a/include/sol/coroutine.hpp +++ b/include/sol/coroutine.hpp @@ -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(lua_resume(lua_state(), nullptr, static_cast(argcount), &nresults)); +#else stats = static_cast(lua_resume(lua_state(), nullptr, static_cast(argcount))); +#endif } template @@ -84,7 +89,7 @@ namespace sol { basic_coroutine() = default; template , basic_coroutine>>, meta::neg>>, meta::neg>, meta::neg>>, is_lua_reference>> = meta::enabler> basic_coroutine(T&& r) noexcept - : base_t(std::forward(r)), error_handler(detail::get_default_handler::value>(r.lua_state())) { + : base_t(std::forward(r)), error_handler(detail::get_default_handler::value>(r.lua_state())) { #if defined(SOL_SAFE_REFERENCES) && SOL_SAFE_REFERENCES if (!is_function>::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& b) - : basic_coroutine(b, detail::get_default_handler::value>(b.lua_state())) { + : basic_coroutine(b, detail::get_default_handler::value>(b.lua_state())) { } basic_coroutine(basic_function&& b) - : basic_coroutine(std::move(b), detail::get_default_handler::value>(b.lua_state())) { + : basic_coroutine(std::move(b), detail::get_default_handler::value>(b.lua_state())) { } basic_coroutine(const basic_function& b, handler_t eh) - : base_t(b), error_handler(std::move(eh)) { + : base_t(b), error_handler(std::move(eh)) { } basic_coroutine(basic_function&& 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::value>(r.lua_state())) { + : basic_coroutine(r.lua_state(), r.stack_index(), detail::get_default_handler::value>(r.lua_state())) { } basic_coroutine(stack_reference&& r) - : basic_coroutine(r.lua_state(), r.stack_index(), detail::get_default_handler::value>(r.lua_state())) { + : basic_coroutine(r.lua_state(), r.stack_index(), detail::get_default_handler::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 basic_coroutine(const proxy_base& p) - : basic_coroutine(p, detail::get_default_handler::value>(p.lua_state())) { + : basic_coroutine(p, detail::get_default_handler::value>(p.lua_state())) { } template basic_coroutine(proxy_base&& p) - : basic_coroutine(std::move(p), detail::get_default_handler::value>(p.lua_state())) { + : basic_coroutine(std::move(p), detail::get_default_handler::value>(p.lua_state())) { } template >, meta::neg>>> = meta::enabler> basic_coroutine(Proxy&& p, Handler&& eh) - : basic_coroutine(detail::force_cast(p), std::forward(eh)) { + : basic_coroutine(detail::force_cast(p), std::forward(eh)) { } template >> = meta::enabler> basic_coroutine(lua_State* L, T&& r) - : basic_coroutine(L, std::forward(r), detail::get_default_handler::value>(L)) { + : basic_coroutine(L, std::forward(r), detail::get_default_handler::value>(L)) { } template >> = meta::enabler> basic_coroutine(lua_State* L, T&& r, handler_t eh) - : base_t(L, std::forward(r)), error_handler(std::move(eh)) { + : base_t(L, std::forward(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::value>(L)) { + : basic_coroutine(L, index, detail::get_default_handler::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(L, index, handler); #endif // Safety } basic_coroutine(lua_State* L, absolute_index index) - : basic_coroutine(L, index, detail::get_default_handler::value>(L)) { + : basic_coroutine(L, index, detail::get_default_handler::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(L, index, handler); #endif // Safety } basic_coroutine(lua_State* L, raw_index index) - : basic_coroutine(L, index, detail::get_default_handler::value>(L)) { + : basic_coroutine(L, index, detail::get_default_handler::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(L, index, handler); #endif // Safety } basic_coroutine(lua_State* L, ref_index index) - : basic_coroutine(L, index, detail::get_default_handler::value>(L)) { + : basic_coroutine(L, index, detail::get_default_handler::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{}; diff --git a/include/sol/stack_core.hpp b/include/sol/stack_core.hpp index 6907d552..83910f13 100644 --- a/include/sol/stack_core.hpp +++ b/include/sol/stack_core.hpp @@ -502,9 +502,7 @@ namespace sol { return &usertype_alloc_destruct; } } - else { - return &cannot_destruct; - } + return &cannot_destruct; } struct no_comp { diff --git a/include/sol/usertype_core.hpp b/include/sol/usertype_core.hpp index 8f852dc7..f2dd8377 100644 --- a/include/sol/usertype_core.hpp +++ b/include/sol/usertype_core.hpp @@ -131,7 +131,9 @@ namespace sol { int index = 0; detail::indexed_insert insert_fx(l, index); detail::insert_default_registrations

(insert_fx, detail::property_always_true); - l[index] = luaL_Reg{ to_string(meta_function::garbage_collect).c_str(), detail::make_destructor

() }; + if constexpr (!std::is_pointer_v) { + l[index] = luaL_Reg{ to_string(meta_function::garbage_collect).c_str(), detail::make_destructor

() }; + } luaL_setfuncs(L, l, 0); // __type table diff --git a/include/sol/usertype_storage.hpp b/include/sol/usertype_storage.hpp index e0bd5bd6..3aecf82f 100644 --- a/include/sol/usertype_storage.hpp +++ b/include/sol/usertype_storage.hpp @@ -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)); - 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_; - ics.new_index = &b.index_call_with_; + ics.index = is_index ? &b.call_with_ : &b.index_call_with_; + ics.new_index = is_new_index ? &b.call_with_ : &b.index_call_with_; // 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(L, s, make_closure(&b.call, nullptr, ics.binding_data), t.stack_index()); } - if (is_index || is_new_index) { + if (poison_indexing) { change_indexing(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::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(mf)] = true; diff --git a/tests/test_operators.cpp b/tests/test_operators.cpp index a7f52286..7e067255 100644 --- a/tests/test_operators.cpp +++ b/tests/test_operators.cpp @@ -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"); - { - 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 diff --git a/tests/tests.cpp b/tests/tests.cpp index f53bf1bd..52e8e6d7 100644 --- a/tests/tests.cpp +++ b/tests/tests.cpp @@ -41,6 +41,25 @@ bool func_opt_ret_bool(sol::optional 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 utdo = lua.new_usertype("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", @@ -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); }