diff options
author | Loïc Blot <nerzhul@users.noreply.github.com> | 2017-05-07 12:13:15 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-05-07 12:13:15 +0200 |
commit | c1b3ed4180dea16e2fa77663a7d2bf155595dd60 (patch) | |
tree | 2cb74486cb3a493716be611ca4cf44d666dec3bf /src | |
parent | 0d7c37943bf29b2c4956576c15efa796d5b5f2d4 (diff) | |
download | minetest-c1b3ed4180dea16e2fa77663a7d2bf155595dd60.tar.gz minetest-c1b3ed4180dea16e2fa77663a7d2bf155595dd60.tar.bz2 minetest-c1b3ed4180dea16e2fa77663a7d2bf155595dd60.zip |
Player attrs: permits to remove an attribute by setting value to nil (#5716)
* Player attrs: permits to remove an attribute by setting value to nil
When doing player:set_attribute("attr", nil) remove attribute
Also remove a useless check on C++ API part (already done by checkplayer)
Fix #5709
Diffstat (limited to 'src')
-rw-r--r-- | src/content_sao.h | 10 | ||||
-rw-r--r-- | src/script/lua_api/l_object.cpp | 7 |
2 files changed, 14 insertions, 3 deletions
diff --git a/src/content_sao.h b/src/content_sao.h index e08795579..0dad54805 100644 --- a/src/content_sao.h +++ b/src/content_sao.h @@ -277,6 +277,16 @@ public: return true; } + inline void removeExtendedAttribute(const std::string &attr) + { + PlayerAttributes::iterator it = m_extra_attributes.find(attr); + if (it == m_extra_attributes.end()) + return; + + m_extra_attributes.erase(it); + m_extended_attributes_modified = true; + } + inline const PlayerAttributes &getExtendedAttributes() { return m_extra_attributes; diff --git a/src/script/lua_api/l_object.cpp b/src/script/lua_api/l_object.cpp index 6f61ab55c..c7a31d048 100644 --- a/src/script/lua_api/l_object.cpp +++ b/src/script/lua_api/l_object.cpp @@ -1202,9 +1202,10 @@ int ObjectRef::l_set_attribute(lua_State *L) } std::string attr = luaL_checkstring(L, 2); - std::string value = luaL_checkstring(L, 3); - - if (co->getType() == ACTIVEOBJECT_TYPE_PLAYER) { + if (lua_isnil(L, 3)) { + co->removeExtendedAttribute(attr); + } else { + std::string value = luaL_checkstring(L, 3); co->setExtendedAttribute(attr, value); } return 1; |