diff options
author | rubenwardy <rubenwardy@gmail.com> | 2017-02-05 18:15:46 +0000 |
---|---|---|
committer | rubenwardy <rubenwardy@gmail.com> | 2017-02-07 21:18:17 +0000 |
commit | 0680c47d6c7d3e98e2b96b823f8cc9ca76d5e7f8 (patch) | |
tree | 46369ef2ae614d022713ee6b30b4de04b0d92938 /src/script/common | |
parent | 8bc6a303b461662b7434a5ee8557292d43682cc9 (diff) | |
download | minetest-0680c47d6c7d3e98e2b96b823f8cc9ca76d5e7f8.tar.gz minetest-0680c47d6c7d3e98e2b96b823f8cc9ca76d5e7f8.tar.bz2 minetest-0680c47d6c7d3e98e2b96b823f8cc9ca76d5e7f8.zip |
Fix incompatibility of ItemStack.to_table() introduced by stack meta
Diffstat (limited to 'src/script/common')
-rw-r--r-- | src/script/common/c_content.cpp | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/script/common/c_content.cpp b/src/script/common/c_content.cpp index 8925b51f4..399aa88d0 100644 --- a/src/script/common/c_content.cpp +++ b/src/script/common/c_content.cpp @@ -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"); |