mirror of
https://github.com/ThePhD/sol2.git
synced 2024-03-22 13:10:44 +08:00
Accidentally put a critical check inside of a SOL_SAFE_USERTYPE define... Buh.
This commit is contained in:
parent
21bc3ef789
commit
ed6ae23d2e
|
@ -132,7 +132,7 @@ namespace sol {
|
|||
return *p.value();
|
||||
#else
|
||||
return stack::get<T>(L, 1);
|
||||
#endif
|
||||
#endif // Safe getting with error
|
||||
}
|
||||
|
||||
static int real_index_call_associative(std::true_type, lua_State* L) {
|
||||
|
@ -171,12 +171,9 @@ namespace sol {
|
|||
using std::begin;
|
||||
auto it = begin(src);
|
||||
K k = *maybek;
|
||||
#ifdef SOL_SAFE_USERTYPE
|
||||
if (k > src.size() || k < 1) {
|
||||
return stack::push(L, lua_nil);
|
||||
}
|
||||
#else
|
||||
#endif // Safety
|
||||
--k;
|
||||
std::advance(it, k);
|
||||
return stack::push_reference(L, *it);
|
||||
|
@ -234,7 +231,7 @@ namespace sol {
|
|||
#ifdef SOL_SAFE_USERTYPE
|
||||
auto maybek = stack::check_get<K>(L, 2);
|
||||
if (!maybek) {
|
||||
return stack::push(L, lua_nil);
|
||||
return 0;
|
||||
}
|
||||
K k = *maybek;
|
||||
#else
|
||||
|
|
|
@ -490,3 +490,35 @@ TEST_CASE("containers/to_args", "Test that the to_args abstractions works") {
|
|||
REQUIRE(d == 12);
|
||||
|
||||
}
|
||||
|
||||
TEST_CASE("containers/ipairs-test", "ensure that abstractions roundtrip properly and push nils to stop pairs / ipairs") {
|
||||
struct thing {
|
||||
int x = 20;
|
||||
};
|
||||
thing t{};
|
||||
sol::state lua;
|
||||
lua.open_libraries();
|
||||
|
||||
lua.set_function("f", [&t]() {
|
||||
return std::vector<thing*>(5, &t);
|
||||
});
|
||||
|
||||
lua.script(R"(
|
||||
c = f()
|
||||
)");
|
||||
|
||||
lua.script(R"(
|
||||
check = {}
|
||||
local i = 1
|
||||
while c[i] do
|
||||
check[i] = v
|
||||
i = i + 1
|
||||
end
|
||||
)");
|
||||
sol::table c = lua["check"];
|
||||
for (std::size_t i = 1; i < 6; ++i) {
|
||||
thing& ct = c[i];
|
||||
REQUIRE(&t == &ct);
|
||||
REQUIRE(ct.x == 20);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user