aboutsummaryrefslogtreecommitdiff
path: root/src/script
diff options
context:
space:
mode:
authorsfan5 <sfan5@live.de>2017-05-10 15:29:21 +0200
committerLoïc Blot <nerzhul@users.noreply.github.com>2017-05-10 15:29:21 +0200
commit071e114ffa945522a7a9acc3259427166992d5ee (patch)
treeb76be5cdc27e9a8d9b58ff15f80691e012afa702 /src/script
parent6945f807abd789e0f522351e5e790ff2afced233 (diff)
downloadminetest-071e114ffa945522a7a9acc3259427166992d5ee.tar.gz
minetest-071e114ffa945522a7a9acc3259427166992d5ee.tar.bz2
minetest-071e114ffa945522a7a9acc3259427166992d5ee.zip
Private nodemeta (#5702)
* Private node metadata that isn't sent to the client
Diffstat (limited to 'src/script')
-rw-r--r--src/script/lua_api/l_nodemeta.cpp27
-rw-r--r--src/script/lua_api/l_nodemeta.h3
2 files changed, 30 insertions, 0 deletions
diff --git a/src/script/lua_api/l_nodemeta.cpp b/src/script/lua_api/l_nodemeta.cpp
index 6232112c5..5dfa6d52e 100644
--- a/src/script/lua_api/l_nodemeta.cpp
+++ b/src/script/lua_api/l_nodemeta.cpp
@@ -94,6 +94,32 @@ int NodeMetaRef::l_get_inventory(lua_State *L)
return 1;
}
+// mark_as_private(self, <string> or {<string>, <string>, ...})
+int NodeMetaRef::l_mark_as_private(lua_State *L)
+{
+ MAP_LOCK_REQUIRED;
+
+ NodeMetaRef *ref = checkobject(L, 1);
+ NodeMetadata *meta = dynamic_cast<NodeMetadata*>(ref->getmeta(true));
+ assert(meta);
+
+ if (lua_istable(L, 2)) {
+ lua_pushnil(L);
+ while (lua_next(L, 2) != 0) {
+ // key at index -2 and value at index -1
+ luaL_checktype(L, -1, LUA_TSTRING);
+ meta->markPrivate(lua_tostring(L, -1), true);
+ // removes value, keeps key for next iteration
+ lua_pop(L, 1);
+ }
+ } else if (lua_isstring(L, 2)) {
+ meta->markPrivate(lua_tostring(L, 2), true);
+ }
+ ref->reportMetadataChange();
+
+ return 0;
+}
+
void NodeMetaRef::handleToTable(lua_State *L, Metadata *_meta)
{
// fields
@@ -229,6 +255,7 @@ const luaL_Reg NodeMetaRef::methodsServer[] = {
luamethod(MetaDataRef, to_table),
luamethod(MetaDataRef, from_table),
luamethod(NodeMetaRef, get_inventory),
+ luamethod(NodeMetaRef, mark_as_private),
luamethod(MetaDataRef, equals),
{0,0}
};
diff --git a/src/script/lua_api/l_nodemeta.h b/src/script/lua_api/l_nodemeta.h
index 2ac028079..dd4260ff9 100644
--- a/src/script/lua_api/l_nodemeta.h
+++ b/src/script/lua_api/l_nodemeta.h
@@ -73,6 +73,9 @@ private:
// get_inventory(self)
static int l_get_inventory(lua_State *L);
+ // mark_as_private(self, <string> or {<string>, <string>, ...})
+ static int l_mark_as_private(lua_State *L);
+
public:
NodeMetaRef(v3s16 p, ServerEnvironment *env);
NodeMetaRef(Metadata *meta);