From 7744a49cfe0f15d668e41d99e3a272df122a1f3f Mon Sep 17 00:00:00 2001 From: ThePhD Date: Wed, 17 Aug 2016 15:47:18 -0400 Subject: [PATCH] I can spell good I promise update bootstrap to properly use depsfile --- bootstrap.py | 8 +++++--- sol/stack_get.hpp | 4 ++-- test_tables.cpp | 52 ++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 58 insertions(+), 6 deletions(-) diff --git a/bootstrap.py b/bootstrap.py index 7bb9304a..f2202a67 100755 --- a/bootstrap.py +++ b/bootstrap.py @@ -165,11 +165,13 @@ ninja.newline() ninja.rule('bootstrap', command = ' '.join(['python'] + sys.argv), generator = True) ninja.rule('compile', command = '$cxx -MMD -MF $out.d -c $cxxflags -Werror $in -o $out', deps = 'gcc', depfile = '$out.d', - description = 'Compiling $in to $out') -ninja.rule('link', command = '$cxx $cxxflags $in -o $out $ldflags', description = 'Creating $out') + description = 'compiling $in to $out') +ninja.rule('link', command = '$cxx $cxxflags $in -o $out $ldflags', description = 'creating $out') ninja.rule('tests_runner', command = tests) ninja.rule('examples_runner', command = 'cmd /c ' + (' && '.join(examples)) if 'win32' in sys.platform else ' && '.join(examples) ) -ninja.rule('example', command = '$cxx $cxxflags $in -o $out $ldflags') +ninja.rule('example', command = '$cxx $cxxflags -MMD -MF $out.d $in -o $out $ldflags', + deps = 'gcc', depfile = '$out.d', + description = 'compiling example $in to $out') ninja.rule('installer', command = copy_command) ninja.rule('uninstaller', command = remove_command) ninja.newline() diff --git a/sol/stack_get.hpp b/sol/stack_get.hpp index b346ffe2..06434b39 100644 --- a/sol/stack_get.hpp +++ b/sol/stack_get.hpp @@ -113,12 +113,12 @@ namespace sol { index = lua_absindex(L, index); lua_pushnil(L); while (lua_next(L, index) != 0) { - decltype(auto) key = stack::check_get(L, -1); + decltype(auto) key = stack::check_get(L, -2); if (!key) { lua_pop(L, 1); continue; } - arr.emplace(std::forward(key), stack::get(L, -1)); + associative.emplace(std::forward(*key), stack::get(L, -1)); lua_pop(L, 1); } return associative; diff --git a/test_tables.cpp b/test_tables.cpp index fc478fd8..afa53eb6 100644 --- a/test_tables.cpp +++ b/test_tables.cpp @@ -3,11 +3,13 @@ #include #include #include -#include #include #include #include #include +#include +#include +#include #include "test_stack_guard.hpp" std::string free_function() { @@ -573,3 +575,51 @@ TEST_CASE("tables/returns", "make sure that even references to vectors are being matching = t[3] == 3; REQUIRE(matching); } + +TEST_CASE("tables/vector_roundtrip", "make sure vectors can be round-tripped") { + sol::state lua; + std::vector v{ 1, 2, 3 }; + lua.set_function("f", [&]() -> std::vector& { + return v; + }); + lua.script("x = f()"); + std::vector x = lua["x"]; + bool areequal = x == v; + REQUIRE(areequal); +} + +TEST_CASE("tables/list_roundtrip", "make sure lists can be round-tripped") { + sol::state lua; + std::list v{ 1, 2, 3 }; + lua.set_function("f", [&]() -> std::list& { + return v; + }); + lua.script("x = f()"); + std::list x = lua["x"]; + bool areequal = x == v; + REQUIRE(areequal); +} + +TEST_CASE("tables/map_roundtrip", "make sure maps can be round-tripped") { + sol::state lua; + std::map v{ { "a", 1 },{ "b", 2 },{ "c", 3 } }; + lua.set_function("f", [&]() -> std::map& { + return v; + }); + lua.script("x = f()"); + std::map x = lua["x"]; + bool areequal = x == v; + REQUIRE(areequal); +} + +TEST_CASE("tables/unordered_map_roundtrip", "make sure unordered_maps can be round-tripped") { + sol::state lua; + std::unordered_map v{ { "a", 1 },{ "b", 2 },{ "c", 3 } }; + lua.set_function("f", [&]() -> std::unordered_map& { + return v; + }); + lua.script("x = f()"); + std::unordered_map x = lua["x"]; + bool areequal = x == v; + REQUIRE(areequal); +}