From: rubenwardy Date: Tue, 31 Jan 2017 16:18:45 +0000 (+0000) Subject: Make NodeMetaRef::getmeta a non-static member X-Git-Tag: 0.4.16~462 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=13f94ecad5d4fcda08663ee91e45b4a205a1dadb;p=oweals%2Fminetest.git Make NodeMetaRef::getmeta a non-static member --- diff --git a/src/script/lua_api/l_nodemeta.cpp b/src/script/lua_api/l_nodemeta.cpp index 631aa68ce..8391de03c 100644 --- a/src/script/lua_api/l_nodemeta.cpp +++ b/src/script/lua_api/l_nodemeta.cpp @@ -36,12 +36,12 @@ NodeMetaRef* NodeMetaRef::checkobject(lua_State *L, int narg) return *(NodeMetaRef**)ud; // unbox pointer } -NodeMetadata* NodeMetaRef::getmeta(NodeMetaRef *ref, bool auto_create) +NodeMetadata* NodeMetaRef::getmeta(bool auto_create) { - NodeMetadata *meta = ref->m_env->getMap().getNodeMetadata(ref->m_p); - if(meta == NULL && auto_create) { - meta = new NodeMetadata(ref->m_env->getGameDef()->idef()); - if(!ref->m_env->getMap().setNodeMetadata(ref->m_p, meta)) { + NodeMetadata *meta = m_env->getMap().getNodeMetadata(m_p); + if (meta == NULL && auto_create) { + meta = new NodeMetadata(m_env->getGameDef()->idef()); + if (!m_env->getMap().setNodeMetadata(m_p, meta)) { delete meta; return NULL; } @@ -83,7 +83,7 @@ int NodeMetaRef::l_get_string(lua_State *L) NodeMetaRef *ref = checkobject(L, 1); std::string name = luaL_checkstring(L, 2); - NodeMetadata *meta = getmeta(ref, false); + NodeMetadata *meta = ref->getmeta(false); if(meta == NULL){ lua_pushlstring(L, "", 0); return 1; @@ -104,7 +104,7 @@ int NodeMetaRef::l_set_string(lua_State *L) const char *s = lua_tolstring(L, 3, &len); std::string str(s, len); - NodeMetadata *meta = getmeta(ref, !str.empty()); + NodeMetadata *meta = ref->getmeta(!str.empty()); if(meta == NULL || str == meta->getString(name)) return 0; meta->setString(name, str); @@ -120,7 +120,7 @@ int NodeMetaRef::l_get_int(lua_State *L) NodeMetaRef *ref = checkobject(L, 1); std::string name = lua_tostring(L, 2); - NodeMetadata *meta = getmeta(ref, false); + NodeMetadata *meta = ref->getmeta(false); if(meta == NULL){ lua_pushnumber(L, 0); return 1; @@ -140,7 +140,7 @@ int NodeMetaRef::l_set_int(lua_State *L) int a = lua_tointeger(L, 3); std::string str = itos(a); - NodeMetadata *meta = getmeta(ref, true); + NodeMetadata *meta = ref->getmeta(true); if(meta == NULL || str == meta->getString(name)) return 0; meta->setString(name, str); @@ -156,7 +156,7 @@ int NodeMetaRef::l_get_float(lua_State *L) NodeMetaRef *ref = checkobject(L, 1); std::string name = lua_tostring(L, 2); - NodeMetadata *meta = getmeta(ref, false); + NodeMetadata *meta = ref->getmeta(false); if(meta == NULL){ lua_pushnumber(L, 0); return 1; @@ -176,7 +176,7 @@ int NodeMetaRef::l_set_float(lua_State *L) float a = lua_tonumber(L, 3); std::string str = ftos(a); - NodeMetadata *meta = getmeta(ref, true); + NodeMetadata *meta = ref->getmeta(true); if(meta == NULL || str == meta->getString(name)) return 0; meta->setString(name, str); @@ -190,7 +190,7 @@ int NodeMetaRef::l_get_inventory(lua_State *L) MAP_LOCK_REQUIRED; NodeMetaRef *ref = checkobject(L, 1); - getmeta(ref, true); // try to ensure the metadata exists + ref->getmeta(true); // try to ensure the metadata exists InvRef::createNodeMeta(L, ref->m_p); return 1; } @@ -202,7 +202,7 @@ int NodeMetaRef::l_to_table(lua_State *L) NodeMetaRef *ref = checkobject(L, 1); - NodeMetadata *meta = getmeta(ref, true); + NodeMetadata *meta = ref->getmeta(true); if (meta == NULL) { lua_pushnil(L); return 1; @@ -257,7 +257,7 @@ int NodeMetaRef::l_from_table(lua_State *L) } // Create new metadata - NodeMetadata *meta = getmeta(ref, true); + NodeMetadata *meta = ref->getmeta(true); if (meta == NULL) { lua_pushboolean(L, false); return 1; diff --git a/src/script/lua_api/l_nodemeta.h b/src/script/lua_api/l_nodemeta.h index e39ac3931..4ce338b18 100644 --- a/src/script/lua_api/l_nodemeta.h +++ b/src/script/lua_api/l_nodemeta.h @@ -52,7 +52,7 @@ private: * @param auto_create when true, try to create metadata information for the node if it has none. * @return pointer to a @c NodeMetadata object or @c NULL in case of error. */ - static NodeMetadata* getmeta(NodeMetaRef *ref, bool auto_create); + virtual NodeMetadata* getmeta(bool auto_create); static void reportMetadataChange(NodeMetaRef *ref);