tables and userdata and pairs and ipairs, oh my

This commit is contained in:
ThePhD 2016-08-24 08:31:18 -04:00
parent cf76f6baa0
commit 54cffb7b6d
3 changed files with 10 additions and 10 deletions

View File

@ -295,7 +295,6 @@ namespace sol {
iter& i = stack::get<user<iter>>(L, 1);
auto& source = i.source;
auto& it = i.it;
K k = stack::get<K>(L, 2);
std::advance(it, 1);
if (it == end(source)) {
return 0;

View File

@ -238,17 +238,17 @@ namespace sol {
load_result load(const std::string& code) {
load_status x = static_cast<load_status>(luaL_loadstring(L, code.c_str()));
return load_result(L, -1, 1, 1, x);
return load_result(L, lua_absindex(L, -1), 1, 1, x);
}
load_result load_file(const std::string& filename) {
load_status x = static_cast<load_status>(luaL_loadfile(L, filename.c_str()));
return load_result(L, -1, 1, 1, x);
return load_result(L, lua_absindex(L, -1), 1, 1, x);
}
load_result load_buffer(const char *buff, size_t size, const char *name, const char* mode = nullptr) {
load_status x = static_cast<load_status>(luaL_loadbufferx(L, buff, size, name, mode));
return load_result(L, -1, 1, 1, x);
return load_result(L, lua_absindex(L, -1), 1, 1, x);
}
iterator begin() const {

View File

@ -129,20 +129,20 @@ TEST_CASE("containers/basic-serialization", "make sure containers are turned int
lua.open_libraries();
lua.set("b", woof{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30 });
REQUIRE_NOTHROW(
lua.script("for k, v in pairs(b) do assert(k == v) end");
lua.script("for k = 1, #b do assert(k == b[k]) end");
);
woof w{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30 };
lua.set("b", w);
REQUIRE_NOTHROW(
lua.script("for k, v in pairs(b) do assert(k == v) end");
lua.script("for k = 1, #b do assert(k == b[k]) end");
);
lua.set("b", &w);
REQUIRE_NOTHROW(
lua.script("for k, v in pairs(b) do assert(k == v) end");
lua.script("for k = 1, #b do assert(k == b[k]) end");
);
lua.set("b", std::ref(w));
REQUIRE_NOTHROW(
lua.script("for k, v in pairs(b) do assert(k == v) end");
lua.script("for k = 1, #b do assert(k == b[k]) end");
);
}
@ -204,7 +204,8 @@ TEST_CASE("containers/const-correctness", "usertype metatable names should reaso
lua.script(R"(
func = function(vecs)
for i, vec in pairs(vecs) do
for i = 1, #vecs do
vec = vecs[i]
print(i, ":", vec.x, vec.y, vec.z)
end
end
@ -212,7 +213,7 @@ end
REQUIRE_NOTHROW({
lua["func"](foo);
lua["func"](bar);
lua["func"](bar);
});
}