summaryrefslogtreecommitdiff
path: root/src/script/lua_api/l_nodemeta.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/script/lua_api/l_nodemeta.cpp')
-rw-r--r--src/script/lua_api/l_nodemeta.cpp27
1 files changed, 27 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}
};