diff --git a/include/sol/error_handler.hpp b/include/sol/error_handler.hpp index 7e019cc9..27ac5258 100644 --- a/include/sol/error_handler.hpp +++ b/include/sol/error_handler.hpp @@ -34,9 +34,9 @@ namespace sol { namespace detail { constexpr const char* not_a_number = "not a numeric type"; constexpr const char* not_a_number_or_number_string = "not a numeric type or numeric string"; - constexpr const char* not_a_number_integral = "not a numeric type that fits exactly an integer (has significant decimals)"; + constexpr const char* not_a_number_integral = "not a numeric type that fits exactly an integer (number maybe has significant decimals)"; constexpr const char* not_a_number_or_number_string_integral - = "not a numeric type or a numeric string that fits exactly an integer (has significant decimals)"; + = "not a numeric type or a numeric string that fits exactly an integer (e.g. number maybe has significant decimals)"; constexpr const char* not_enough_stack_space = "not enough space left on Lua stack"; constexpr const char* not_enough_stack_space_floating = "not enough space left on Lua stack for a floating point number"; @@ -138,7 +138,7 @@ namespace sol { aux_message += detail::demangle(); aux_message += "("; int marker = 0; - (void)detail::swallow{ int(), (detail::accumulate_and_mark(detail::demangle(), aux_message, marker), int())... }; + (void)detail::swallow { int(), (detail::accumulate_and_mark(detail::demangle(), aux_message, marker), int())... }; aux_message += ")')"; push_type_panic_string(L, index, expected, actual, message, aux_message); } diff --git a/include/sol/usertype_container.hpp b/include/sol/usertype_container.hpp index 5dda246d..fad06ff2 100644 --- a/include/sol/usertype_container.hpp +++ b/include/sol/usertype_container.hpp @@ -356,10 +356,10 @@ namespace sol { using has_traits_erase = meta::boolean::value>; template - struct is_forced_container : is_container {}; + struct is_forced_container : is_container { }; template - struct is_forced_container> : std::true_type {}; + struct is_forced_container> : std::true_type { }; template struct container_decay { @@ -880,8 +880,7 @@ namespace sol { auto backit = self.before_begin(); { auto e = deferred_uc::end(L, self); - for (auto it = deferred_uc::begin(L, self); it != e; ++backit, ++it) { - } + for (auto it = deferred_uc::begin(L, self); it != e; ++backit, ++it) { } } return add_insert_after(std::true_type(), L, self, value, backit); } @@ -1244,8 +1243,22 @@ namespace sol { static int set(lua_State* L) { stack_object value = stack_object(L, raw_index(3)); - if (type_of(L, 3) == type::lua_nil) { - return erase(L); + if constexpr (is_linear_integral::value) { + // for non-associative containers, + // erasure only happens if it is the + // last index in the container + auto key = stack::get(L, 2); + auto self_size = deferred_uc::size(L); + if (key == static_cast(self_size)) { + if (type_of(L, 3) == type::lua_nil) { + return erase(L); + } + } + } + else { + if (type_of(L, 3) == type::lua_nil) { + return erase(L); + } } auto& self = get_src(L); detail::error_result er = set_start(L, self, stack_object(L, raw_index(2)), std::move(value)); @@ -1522,11 +1535,11 @@ namespace sol { }; template - struct usertype_container_default> : usertype_container_default {}; + struct usertype_container_default> : usertype_container_default { }; } // namespace container_detail template - struct usertype_container : container_detail::usertype_container_default {}; + struct usertype_container : container_detail::usertype_container_default { }; } // namespace sol diff --git a/single/include/sol/forward.hpp b/single/include/sol/forward.hpp index f97c41d4..e172e86a 100644 --- a/single/include/sol/forward.hpp +++ b/single/include/sol/forward.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 2020-03-31 04:18:52.546413 UTC -// This header was generated with sol v3.2.0 (revision 82812c5) +// Generated 2020-05-07 02:16:42.603409 UTC +// This header was generated with sol v3.2.0 (revision 890cdd3) // https://github.com/ThePhD/sol2 #ifndef SOL_SINGLE_INCLUDE_FORWARD_HPP diff --git a/single/include/sol/sol.hpp b/single/include/sol/sol.hpp index d1d24bdf..c3e9bef0 100644 --- a/single/include/sol/sol.hpp +++ b/single/include/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 2020-03-31 04:18:51.740568 UTC -// This header was generated with sol v3.2.0 (revision 82812c5) +// Generated 2020-05-07 02:16:42.137643 UTC +// This header was generated with sol v3.2.0 (revision 890cdd3) // https://github.com/ThePhD/sol2 #ifndef SOL_SINGLE_INCLUDE_HPP @@ -8054,9 +8054,9 @@ namespace sol { namespace detail { constexpr const char* not_a_number = "not a numeric type"; constexpr const char* not_a_number_or_number_string = "not a numeric type or numeric string"; - constexpr const char* not_a_number_integral = "not a numeric type that fits exactly an integer (has significant decimals)"; + constexpr const char* not_a_number_integral = "not a numeric type that fits exactly an integer (number maybe has significant decimals)"; constexpr const char* not_a_number_or_number_string_integral - = "not a numeric type or a numeric string that fits exactly an integer (has significant decimals)"; + = "not a numeric type or a numeric string that fits exactly an integer (e.g. number maybe has significant decimals)"; constexpr const char* not_enough_stack_space = "not enough space left on Lua stack"; constexpr const char* not_enough_stack_space_floating = "not enough space left on Lua stack for a floating point number"; @@ -8158,7 +8158,7 @@ namespace sol { aux_message += detail::demangle(); aux_message += "("; int marker = 0; - (void)detail::swallow{ int(), (detail::accumulate_and_mark(detail::demangle(), aux_message, marker), int())... }; + (void)detail::swallow { int(), (detail::accumulate_and_mark(detail::demangle(), aux_message, marker), int())... }; aux_message += ")')"; push_type_panic_string(L, index, expected, actual, message, aux_message); } @@ -19231,10 +19231,10 @@ namespace sol { using has_traits_erase = meta::boolean::value>; template - struct is_forced_container : is_container {}; + struct is_forced_container : is_container { }; template - struct is_forced_container> : std::true_type {}; + struct is_forced_container> : std::true_type { }; template struct container_decay { @@ -19755,8 +19755,7 @@ namespace sol { auto backit = self.before_begin(); { auto e = deferred_uc::end(L, self); - for (auto it = deferred_uc::begin(L, self); it != e; ++backit, ++it) { - } + for (auto it = deferred_uc::begin(L, self); it != e; ++backit, ++it) { } } return add_insert_after(std::true_type(), L, self, value, backit); } @@ -20119,8 +20118,22 @@ namespace sol { static int set(lua_State* L) { stack_object value = stack_object(L, raw_index(3)); - if (type_of(L, 3) == type::lua_nil) { - return erase(L); + if constexpr (is_linear_integral::value) { + // for non-associative containers, + // erasure only happens if it is the + // last index in the container + auto key = stack::get(L, 2); + auto self_size = deferred_uc::size(L); + if (key == static_cast(self_size)) { + if (type_of(L, 3) == type::lua_nil) { + return erase(L); + } + } + } + else { + if (type_of(L, 3) == type::lua_nil) { + return erase(L); + } } auto& self = get_src(L); detail::error_result er = set_start(L, self, stack_object(L, raw_index(2)), std::move(value)); @@ -20397,11 +20410,11 @@ namespace sol { }; template - struct usertype_container_default> : usertype_container_default {}; + struct usertype_container_default> : usertype_container_default { }; } // namespace container_detail template - struct usertype_container : container_detail::usertype_container_default {}; + struct usertype_container : container_detail::usertype_container_default { }; } // namespace sol diff --git a/tests/runtime_tests/source/container_shims.cpp b/tests/runtime_tests/source/container_shims.cpp index 6e2d93d9..61583254 100644 --- a/tests/runtime_tests/source/container_shims.cpp +++ b/tests/runtime_tests/source/container_shims.cpp @@ -139,7 +139,7 @@ struct my_vec : public std::vector { namespace sol { template <> - struct is_container : std::true_type {}; + struct is_container : std::true_type { }; template <> struct usertype_container { @@ -149,6 +149,12 @@ namespace sol { static auto end(lua_State*, my_vec& self) { return self.end(); } + + static std::size_t size(lua_State* L) { + my_vec& v = sol::stack::get(L, 1); + return v.size(); + } + static std::ptrdiff_t index_adjustment(lua_State*, my_vec&) { return 0; } @@ -202,7 +208,7 @@ TEST_CASE("containers/custom indexing", "allow containers to set a custom indexi sol::state lua; lua.open_libraries(sol::lib::base); - lua["c"] = my_vec{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; + lua["c"] = my_vec { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; auto result1 = lua.safe_script("for i=0,9 do assert(i == c[i]) end", sol::script_pass_on_error); REQUIRE(result1.valid());