mirror of
https://github.com/ThePhD/sol2.git
synced 2024-03-22 13:10:44 +08:00
Improve container handling and the vec[#vec] = nil idiom from Lua
This commit is contained in:
parent
890cdd38b4
commit
5022c4d8f6
|
@ -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";
|
||||
|
|
|
@ -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,9 +1243,23 @@ namespace sol {
|
|||
|
||||
static int set(lua_State* L) {
|
||||
stack_object value = stack_object(L, raw_index(3));
|
||||
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<K>(L, 2);
|
||||
auto self_size = deferred_uc::size(L);
|
||||
if (key == static_cast<K>(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));
|
||||
return handle_errors(L, er);
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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";
|
||||
|
@ -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,9 +20118,23 @@ namespace sol {
|
|||
|
||||
static int set(lua_State* L) {
|
||||
stack_object value = stack_object(L, raw_index(3));
|
||||
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<K>(L, 2);
|
||||
auto self_size = deferred_uc::size(L);
|
||||
if (key == static_cast<K>(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));
|
||||
return handle_errors(L, er);
|
||||
|
|
|
@ -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<my_vec&>(L, 1);
|
||||
return v.size();
|
||||
}
|
||||
|
||||
static std::ptrdiff_t index_adjustment(lua_State*, my_vec&) {
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user