aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrubenwardy <rubenwardy@gmail.com>2017-02-19 20:57:46 +0000
committerAuke Kok <sofar+github@foo-projects.org>2017-02-22 10:14:12 -0800
commit2d1fca51e975a01f84fa3fd9b266435316fbe548 (patch)
tree7a22fcbe40d0c39ada653dd31f20b284496a1ade
parent01b2d2c66c9095341554400ba67505b137ec1d86 (diff)
downloadminetest-2d1fca51e975a01f84fa3fd9b266435316fbe548.tar.gz
minetest-2d1fca51e975a01f84fa3fd9b266435316fbe548.tar.bz2
minetest-2d1fca51e975a01f84fa3fd9b266435316fbe548.zip
Fix wrong meta key in item meta on ItemStack construction
-rw-r--r--src/script/common/c_content.cpp28
1 files changed, 6 insertions, 22 deletions
diff --git a/src/script/common/c_content.cpp b/src/script/common/c_content.cpp
index 399aa88d0..a963856b7 100644
--- a/src/script/common/c_content.cpp
+++ b/src/script/common/c_content.cpp
@@ -827,29 +827,13 @@ ItemStack read_item(lua_State* L, int index,Server* srv)
ItemStack istack(name, count, wear, idef);
- lua_getfield(L, index, "metadata");
-
- // Support old metadata format by checking type
- int 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
- }
- } else {
- // BACKWARDS COMPATIBLITY
- std::string value = getstringfield_default(L, index, "metadata", "");
- istack.metadata.setString("", value);
- }
+ // BACKWARDS COMPATIBLITY
+ std::string value = getstringfield_default(L, index, "metadata", "");
+ istack.metadata.setString("", value);
+ // Get meta
lua_getfield(L, index, "meta");
- fieldstable = lua_gettop(L);
+ int fieldstable = lua_gettop(L);
if (lua_istable(L, fieldstable)) {
lua_pushnil(L);
while (lua_next(L, fieldstable) != 0) {
@@ -858,7 +842,7 @@ ItemStack read_item(lua_State* L, int index,Server* srv)
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);
+ istack.metadata.setString(key, value);
lua_pop(L, 1); // removes value, keeps key for next iteration
}
}