summaryrefslogtreecommitdiff
path: root/src/script/lua_api/l_object.cpp
diff options
context:
space:
mode:
authorrubenwardy <rw@rubenwardy.com>2018-04-06 09:52:29 +0100
committerLoïc Blot <nerzhul@users.noreply.github.com>2018-04-06 10:52:29 +0200
commit91615f9588420fd716978552fdacf1323b8df11c (patch)
tree951b1c139c09056d0d31bc4b8e0d13fd2d69c8bb /src/script/lua_api/l_object.cpp
parent7e3f88f539109955b21a129e4203a1cadb913483 (diff)
downloadminetest-91615f9588420fd716978552fdacf1323b8df11c.tar.gz
minetest-91615f9588420fd716978552fdacf1323b8df11c.tar.bz2
minetest-91615f9588420fd716978552fdacf1323b8df11c.zip
Add player:get_meta(), deprecate player attributes (#7202)
* Add player:get_meta(), deprecate player attributes
Diffstat (limited to 'src/script/lua_api/l_object.cpp')
-rw-r--r--src/script/lua_api/l_object.cpp27
1 files changed, 20 insertions, 7 deletions
diff --git a/src/script/lua_api/l_object.cpp b/src/script/lua_api/l_object.cpp
index 52bb0a784..0bef23541 100644
--- a/src/script/lua_api/l_object.cpp
+++ b/src/script/lua_api/l_object.cpp
@@ -22,6 +22,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "lua_api/l_internal.h"
#include "lua_api/l_inventory.h"
#include "lua_api/l_item.h"
+#include "lua_api/l_playermeta.h"
#include "common/c_converter.h"
#include "common/c_content.h"
#include "log.h"
@@ -1218,16 +1219,15 @@ int ObjectRef::l_set_attribute(lua_State *L)
{
ObjectRef *ref = checkobject(L, 1);
PlayerSAO* co = getplayersao(ref);
- if (co == NULL) {
+ if (co == NULL)
return 0;
- }
std::string attr = luaL_checkstring(L, 2);
if (lua_isnil(L, 3)) {
- co->removeExtendedAttribute(attr);
+ co->getMeta().removeString(attr);
} else {
std::string value = luaL_checkstring(L, 3);
- co->setExtendedAttribute(attr, value);
+ co->getMeta().setString(attr, value);
}
return 1;
}
@@ -1237,14 +1237,13 @@ int ObjectRef::l_get_attribute(lua_State *L)
{
ObjectRef *ref = checkobject(L, 1);
PlayerSAO* co = getplayersao(ref);
- if (co == NULL) {
+ if (co == NULL)
return 0;
- }
std::string attr = luaL_checkstring(L, 2);
std::string value;
- if (co->getExtendedAttribute(attr, &value)) {
+ if (co->getMeta().getStringToRef(attr, value)) {
lua_pushstring(L, value.c_str());
return 1;
}
@@ -1253,6 +1252,19 @@ int ObjectRef::l_get_attribute(lua_State *L)
}
+// get_meta(self, attribute)
+int ObjectRef::l_get_meta(lua_State *L)
+{
+ ObjectRef *ref = checkobject(L, 1);
+ PlayerSAO *co = getplayersao(ref);
+ if (co == NULL)
+ return 0;
+
+ PlayerMetaRef::create(L, &co->getMeta());
+ return 1;
+}
+
+
// set_inventory_formspec(self, formspec)
int ObjectRef::l_set_inventory_formspec(lua_State *L)
{
@@ -1884,6 +1896,7 @@ const luaL_Reg ObjectRef::methods[] = {
luamethod(ObjectRef, set_breath),
luamethod(ObjectRef, get_attribute),
luamethod(ObjectRef, set_attribute),
+ luamethod(ObjectRef, get_meta),
luamethod(ObjectRef, set_inventory_formspec),
luamethod(ObjectRef, get_inventory_formspec),
luamethod(ObjectRef, set_formspec_prepend),