1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

Fix incompatibility of ItemStack.to_table() introduced by stack meta

This commit is contained in:
rubenwardy 2017-02-05 18:15:46 +00:00
parent 8bc6a303b4
commit 0680c47d6c
2 changed files with 28 additions and 15 deletions

View file

@ -848,6 +848,21 @@ ItemStack read_item(lua_State* L, int index,Server* srv)
istack.metadata.setString("", value);
}
lua_getfield(L, index, "meta");
fieldstable = lua_gettop(L);
if (lua_istable(L, fieldstable)) {
lua_pushnil(L);
while (lua_next(L, fieldstable) != 0) {
// key at index -2 and value at index -1
std::string key = lua_tostring(L, -2);
size_t value_len;
const char *value_cs = lua_tolstring(L, -1, &value_len);
std::string value(value_cs, value_len);
istack.metadata.setString(name, value);
lua_pop(L, 1); // removes value, keeps key for next iteration
}
}
return istack;
} else {
throw LuaError("Expecting itemstack, itemstring, table or nil");