mirror of
https://github.com/minetest/minetest.git
synced 2024-11-30 19:43:45 +01:00
Fix InventoryList reading order
Lua does not guarantee that the indexes of a table will be in numerical order.
This commit is contained in:
parent
8e1d78e9de
commit
829426c714
@ -892,10 +892,15 @@ std::vector<ItemStack> read_items(lua_State *L, int index,Server* srv)
|
|||||||
std::vector<ItemStack> items;
|
std::vector<ItemStack> items;
|
||||||
luaL_checktype(L, index, LUA_TTABLE);
|
luaL_checktype(L, index, LUA_TTABLE);
|
||||||
lua_pushnil(L);
|
lua_pushnil(L);
|
||||||
while(lua_next(L, index) != 0){
|
while (lua_next(L, index)) {
|
||||||
// key at index -2 and value at index -1
|
s32 key = luaL_checkinteger(L, -2);
|
||||||
items.push_back(read_item(L, -1, srv));
|
if (key < 1) {
|
||||||
// removes value, keeps key for next iteration
|
throw LuaError(NULL, "Invalid inventory list index");
|
||||||
|
}
|
||||||
|
if (items.size() < (u32) key) {
|
||||||
|
items.resize(key);
|
||||||
|
}
|
||||||
|
items[key - 1] = read_item(L, -1, srv);
|
||||||
lua_pop(L, 1);
|
lua_pop(L, 1);
|
||||||
}
|
}
|
||||||
return items;
|
return items;
|
||||||
|
Loading…
Reference in New Issue
Block a user