Keep PlayerMetaRef via name not pointer
This commit is contained in:
@@ -21,6 +21,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
#include "lua_api/l_playermeta.h"
|
||||
#include "lua_api/l_internal.h"
|
||||
#include "common/c_content.h"
|
||||
#include "serverenvironment.h"
|
||||
#include "remoteplayer.h"
|
||||
#include "server/player_sao.h"
|
||||
|
||||
/*
|
||||
PlayerMetaRef
|
||||
@@ -28,12 +31,15 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
|
||||
IMetadata *PlayerMetaRef::getmeta(bool auto_create)
|
||||
{
|
||||
return metadata;
|
||||
auto *player = m_env->getPlayer(m_name);
|
||||
auto *sao = player ? player->getPlayerSAO() : nullptr;
|
||||
return sao ? &sao->getMeta() : nullptr;
|
||||
}
|
||||
|
||||
void PlayerMetaRef::clearMeta()
|
||||
{
|
||||
metadata->clear();
|
||||
if (auto *meta = getmeta(true))
|
||||
meta->clear();
|
||||
}
|
||||
|
||||
void PlayerMetaRef::reportMetadataChange(const std::string *name)
|
||||
@@ -43,9 +49,9 @@ void PlayerMetaRef::reportMetadataChange(const std::string *name)
|
||||
|
||||
// Creates an PlayerMetaRef and leaves it on top of stack
|
||||
// Not callable from Lua; all references are created on the C side.
|
||||
void PlayerMetaRef::create(lua_State *L, IMetadata *metadata)
|
||||
void PlayerMetaRef::create(lua_State *L, ServerEnvironment *env, std::string_view name)
|
||||
{
|
||||
PlayerMetaRef *o = new PlayerMetaRef(metadata);
|
||||
PlayerMetaRef *o = new PlayerMetaRef(env, name);
|
||||
*(void **)(lua_newuserdata(L, sizeof(void *))) = o;
|
||||
luaL_getmetatable(L, className);
|
||||
lua_setmetatable(L, -2);
|
||||
|
||||
Reference in New Issue
Block a user