diff --git a/single/sol/sol.hpp b/single/sol/sol.hpp index 8343d95b..2cb58149 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 2016-08-25 16:51:18.743349 UTC -// This header was generated with sol v2.12.1 (revision 354c267) +// Generated 2016-08-27 12:45:21.542724 UTC +// This header was generated with sol v2.12.1 (revision 580ebc7) // https://github.com/ThePhD/sol2 #ifndef SOL_SINGLE_INCLUDE_HPP @@ -10131,6 +10131,8 @@ namespace sol { typedef std::size_t K; typedef typename T::value_type V; typedef typename T::iterator I; + typedef std::remove_reference_t())> IR; + struct iter { T& source; I it; @@ -10175,12 +10177,14 @@ namespace sol { #endif // Safety } - static int real_new_index_call_const(std::false_type, lua_State* L) { - luaL_error(L, "sol: cannot write to a const value type"); + template > = meta::enabler> + static int real_new_index_call_const(std::integral_constant, lua_State* L) { + luaL_error(L, "sol: cannot write to a const value type or an immutable iterator (e.g., std::set)"); return 0; } - static int real_new_index_call_const(std::true_type, lua_State* L) { + template > = meta::enabler> + static int real_new_index_call_const(std::integral_constant, lua_State* L) { auto& src = get_src(L); #ifdef SOL_SAFE_USERTYPE auto maybek = stack::check_get(L, 2); @@ -10206,7 +10210,7 @@ namespace sol { } static int real_new_index_call(lua_State* L) { - return real_new_index_call_const(meta::neg>(), L); + return real_new_index_call_const(meta::neg, std::is_const>>(), L); } static int real_pairs_next_call(lua_State* L) { diff --git a/sol/container_usertype_metatable.hpp b/sol/container_usertype_metatable.hpp index 9a958d5a..ae506805 100644 --- a/sol/container_usertype_metatable.hpp +++ b/sol/container_usertype_metatable.hpp @@ -73,6 +73,8 @@ namespace sol { typedef std::size_t K; typedef typename T::value_type V; typedef typename T::iterator I; + typedef std::remove_reference_t())> IR; + struct iter { T& source; I it; @@ -117,12 +119,14 @@ namespace sol { #endif // Safety } - static int real_new_index_call_const(std::false_type, lua_State* L) { - luaL_error(L, "sol: cannot write to a const value type"); + template > = meta::enabler> + static int real_new_index_call_const(std::integral_constant, lua_State* L) { + luaL_error(L, "sol: cannot write to a const value type or an immutable iterator (e.g., std::set)"); return 0; } - static int real_new_index_call_const(std::true_type, lua_State* L) { + template > = meta::enabler> + static int real_new_index_call_const(std::integral_constant, lua_State* L) { auto& src = get_src(L); #ifdef SOL_SAFE_USERTYPE auto maybek = stack::check_get(L, 2); @@ -148,7 +152,7 @@ namespace sol { } static int real_new_index_call(lua_State* L) { - return real_new_index_call_const(meta::neg>(), L); + return real_new_index_call_const(meta::neg, std::is_const>>(), L); } static int real_pairs_next_call(lua_State* L) { diff --git a/test_containers.cpp b/test_containers.cpp index 7ef92a3d..d2e97567 100644 --- a/test_containers.cpp +++ b/test_containers.cpp @@ -8,6 +8,8 @@ #include #include #include +#include +#include std::vector test_table_return_one() { return{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; @@ -89,6 +91,30 @@ TEST_CASE("containers/unordered_map_roundtrip", "make sure unordered_maps can be REQUIRE(areequal); } +TEST_CASE("containers/unordered_set_roundtrip", "make sure unordered_sets can be round-tripped") { + sol::state lua; + std::unordered_set v{ 1, 2, 3 }; + lua.set_function("f", [&]() -> std::unordered_set& { + return v; + }); + lua.script("x = f()"); + std::unordered_set x = lua["x"]; + bool areequal = x == v; + REQUIRE(areequal); +} + +TEST_CASE("containers/set_roundtrip", "make sure sets can be round-tripped") { + sol::state lua; + std::set v{ 1, 2, 3 }; + lua.set_function("f", [&]() -> std::set& { + return v; + }); + lua.script("x = f()"); + std::set x = lua["x"]; + bool areequal = x == v; + REQUIRE(areequal); +} + TEST_CASE("containers/custom-usertype", "make sure container usertype metatables can be overridden") { typedef std::unordered_map bark;