mirror of
https://github.com/luanti-org/luanti.git
synced 2025-06-27 16:36:03 +00:00
Private nodemeta (#5702)
* Private node metadata that isn't sent to the client
This commit is contained in:
parent
6945f807ab
commit
071e114ffa
10 changed files with 114 additions and 27 deletions
|
@ -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}
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue