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/lua_api | |
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/lua_api')
-rw-r--r-- | src/script/lua_api/l_item.cpp | 28 |
1 files changed, 13 insertions, 15 deletions
diff --git a/src/script/lua_api/l_item.cpp b/src/script/lua_api/l_item.cpp index f0293bed8..9638740e8 100644 --- a/src/script/lua_api/l_item.cpp +++ b/src/script/lua_api/l_item.cpp @@ -225,23 +225,21 @@ int LuaItemStack::l_to_table(lua_State *L) lua_pushinteger(L, item.wear); lua_setfield(L, -2, "wear"); - if (item.metadata.size() == 1 && item.metadata.contains("")) { - const std::string &value = item.metadata.getString(""); + const std::string &metadata_str = item.metadata.getString(""); + lua_pushlstring(L, metadata_str.c_str(), metadata_str.size()); + lua_setfield(L, -2, "metadata"); + + lua_newtable(L); + const StringMap &fields = item.metadata.getStrings(); + for (StringMap::const_iterator it = fields.begin(); + it != fields.end(); ++it) { + const std::string &name = it->first; + const std::string &value = it->second; + lua_pushlstring(L, name.c_str(), name.size()); lua_pushlstring(L, value.c_str(), value.size()); - lua_setfield(L, -2, "metadata"); - } else { - lua_newtable(L); - const StringMap &fields = item.metadata.getStrings(); - for (StringMap::const_iterator it = fields.begin(); - it != fields.end(); ++it) { - const std::string &name = it->first; - const std::string &value = it->second; - lua_pushlstring(L, name.c_str(), name.size()); - lua_pushlstring(L, value.c_str(), value.size()); - lua_settable(L, -3); - } - lua_setfield(L, -2, "metadata"); + lua_settable(L, -3); } + lua_setfield(L, -2, "meta"); } return 1; } |