Skip to content

Commit

Permalink
fixed ipairs swap bug
Browse files Browse the repository at this point in the history
  • Loading branch information
ThePhD committed Oct 30, 2017
1 parent 882f337 commit 9a0b5ef
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 8 deletions.
10 changes: 5 additions & 5 deletions single/sol/sol.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<push_type>(L, detail::deref(it->second));
std::advance(it, 1);
return p;
Expand Down
6 changes: 3 additions & 3 deletions sol/container_traits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<push_type>(L, detail::deref(it->second));
std::advance(it, 1);
return p;
Expand Down
43 changes: 43 additions & 0 deletions tests/test_container_semantics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,28 @@ void associative_unordered_container_check(sol::state& lua, T& items) {
REQUIRE((v3 == 30));
}

template <typename T>
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 <typename T>
void fixed_container_check(sol::state& lua, T& items) {
{
Expand Down Expand Up @@ -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<bar> 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<std::string, bar*> data({ { "a", a },{ "b", b },{ "c", c } });
std::map<std::string, bar*> reflect;
associative_ordered_container_key_value_check(lua, data, reflect);
}
SECTION("multimap") {
sol::state lua;
std::multimap<std::string, bar*> data({ { "a", a },{ "b", b },{ "c", c } });
std::multimap<std::string, bar*> 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();
Expand Down

0 comments on commit 9a0b5ef

Please sign in to comment.