mirror of
https://github.com/luanti-org/luanti.git
synced 2025-06-27 16:36:03 +00:00
Add player:get_meta(), deprecate player attributes (#7202)
* Add player:get_meta(), deprecate player attributes
This commit is contained in:
parent
7e3f88f539
commit
91615f9588
22 changed files with 314 additions and 70 deletions
|
@ -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),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue