From 9a0b5ef34aaa3215518582a01ab3ebdf97db879a Mon Sep 17 00:00:00 2001 From: ThePhD Date: Mon, 30 Oct 2017 14:38:16 -0400 Subject: [PATCH] fixed ipairs swap bug --- single/sol/sol.hpp | 10 +++---- sol/container_traits.hpp | 6 ++--- tests/test_container_semantics.cpp | 43 ++++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+), 8 deletions(-) diff --git a/single/sol/sol.hpp b/single/sol/sol.hpp index 73ace2c3..4e3aae2b 100644 --- a/single/sol/sol.hpp +++ b/single/sol/sol.hpp @@ -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-10-26 17:14:51.531340 UTC -// This header was generated with sol v2.18.5 (revision 540d322) +// Generated 2017-10-30 18:38:03.122522 UTC +// This header was generated with sol v2.18.5 (revision 882f337) // https://github.com/ThePhD/sol2 #ifndef SOL_SINGLE_INCLUDE_HPP @@ -15337,12 +15337,12 @@ namespace sol { } int p; if (ip) { - p = stack::push_reference(L, it->first); - } - else { ++i.i; p = stack::push_reference(L, i.i); } + else { + p = stack::push_reference(L, it->first); + } p += stack::stack_detail::push_reference(L, detail::deref(it->second)); std::advance(it, 1); return p; diff --git a/sol/container_traits.hpp b/sol/container_traits.hpp index ff0dd70b..c73e9dfb 100644 --- a/sol/container_traits.hpp +++ b/sol/container_traits.hpp @@ -1004,12 +1004,12 @@ namespace sol { } int p; if (ip) { - p = stack::push_reference(L, it->first); - } - else { ++i.i; p = stack::push_reference(L, i.i); } + else { + p = stack::push_reference(L, it->first); + } p += stack::stack_detail::push_reference(L, detail::deref(it->second)); std::advance(it, 1); return p; diff --git a/tests/test_container_semantics.cpp b/tests/test_container_semantics.cpp index fa851543..3197cbb2 100644 --- a/tests/test_container_semantics.cpp +++ b/tests/test_container_semantics.cpp @@ -632,6 +632,28 @@ void associative_unordered_container_check(sol::state& lua, T& items) { REQUIRE((v3 == 30)); } +template +void associative_ordered_container_key_value_check(sol::state& lua, T& data, T& reflect) { + typedef typename T::key_type K; + typedef typename T::mapped_type V; + lua["collect"] = [&reflect](K k, V v) { + reflect.insert({ k, v }); + }; + +#if SOL_LUA_VERSION > 502 + lua["val"] = data; + lua.script(R"( +for k, v in pairs(val) do + collect(k, v) +end +print() +)"); +#else + reflect = data; +#endif + REQUIRE((data == reflect)); +} + template void fixed_container_check(sol::state& lua, T& items) { { @@ -912,6 +934,27 @@ TEST_CASE("containers/associative unordered containers", "check associative (map } } +TEST_CASE("containers/associative ordered pairs", "check to make sure pairs works properly for key-value types") { + struct bar {}; + std::unique_ptr ua(new bar()), ub(new bar()), uc(new bar()); + bar* a = ua.get(); + bar* b = ub.get(); + bar* c = uc.get(); + + SECTION("map") { + sol::state lua; + std::map data({ { "a", a },{ "b", b },{ "c", c } }); + std::map reflect; + associative_ordered_container_key_value_check(lua, data, reflect); + } + SECTION("multimap") { + sol::state lua; + std::multimap data({ { "a", a },{ "b", b },{ "c", c } }); + std::multimap reflect; + associative_ordered_container_key_value_check(lua, data, reflect); + } +} + TEST_CASE("containers/auxiliary functions test", "make sure the manipulation functions are present and usable and working across various container types") { sol::state lua; lua.open_libraries();