mirror of
https://github.com/luanti-org/luanti.git
synced 2025-10-14 00:55:20 +02:00
Add MetaDataRef:get_keys (#12841)
This commit is contained in:
committed by
GitHub
parent
1a045da0dd
commit
cd8a7fe472
@@ -97,6 +97,7 @@ const luaL_Reg ItemStackMetaRef::methods[] = {
|
||||
luamethod(MetaDataRef, set_int),
|
||||
luamethod(MetaDataRef, get_float),
|
||||
luamethod(MetaDataRef, set_float),
|
||||
luamethod(MetaDataRef, get_keys),
|
||||
luamethod(MetaDataRef, to_table),
|
||||
luamethod(MetaDataRef, from_table),
|
||||
luamethod(MetaDataRef, equals),
|
||||
|
@@ -24,6 +24,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
#include "serverenvironment.h"
|
||||
#include "map.h"
|
||||
#include "server.h"
|
||||
#include "util/basic_macros.h"
|
||||
|
||||
MetaDataRef *MetaDataRef::checkAnyMetadata(lua_State *L, int narg)
|
||||
{
|
||||
@@ -196,6 +197,31 @@ int MetaDataRef::l_set_float(lua_State *L)
|
||||
return 0;
|
||||
}
|
||||
|
||||
// get_keys(self)
|
||||
int MetaDataRef::l_get_keys(lua_State *L)
|
||||
{
|
||||
MAP_LOCK_REQUIRED;
|
||||
|
||||
MetaDataRef *ref = checkAnyMetadata(L, 1);
|
||||
|
||||
IMetadata *meta = ref->getmeta(false);
|
||||
if (meta == NULL) {
|
||||
lua_newtable(L);
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::vector<std::string> keys_;
|
||||
const std::vector<std::string> &keys = meta->getKeys(&keys_);
|
||||
|
||||
int i = 0;
|
||||
lua_createtable(L, keys.size(), 0);
|
||||
for (const std::string &key : keys) {
|
||||
lua_pushlstring(L, key.c_str(), key.size());
|
||||
lua_rawseti(L, -2, ++i);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
// to_table(self)
|
||||
int MetaDataRef::l_to_table(lua_State *L)
|
||||
{
|
||||
|
@@ -74,6 +74,9 @@ protected:
|
||||
// set_float(self, name, var)
|
||||
static int l_set_float(lua_State *L);
|
||||
|
||||
// get_keys(self)
|
||||
static int l_get_keys(lua_State *L);
|
||||
|
||||
// to_table(self)
|
||||
static int l_to_table(lua_State *L);
|
||||
|
||||
|
@@ -209,6 +209,7 @@ const luaL_Reg NodeMetaRef::methodsServer[] = {
|
||||
luamethod(MetaDataRef, set_int),
|
||||
luamethod(MetaDataRef, get_float),
|
||||
luamethod(MetaDataRef, set_float),
|
||||
luamethod(MetaDataRef, get_keys),
|
||||
luamethod(MetaDataRef, to_table),
|
||||
luamethod(MetaDataRef, from_table),
|
||||
luamethod(NodeMetaRef, get_inventory),
|
||||
@@ -230,6 +231,7 @@ const luaL_Reg NodeMetaRef::methodsClient[] = {
|
||||
luamethod(MetaDataRef, get_string),
|
||||
luamethod(MetaDataRef, get_int),
|
||||
luamethod(MetaDataRef, get_float),
|
||||
luamethod(MetaDataRef, get_keys),
|
||||
luamethod(MetaDataRef, to_table),
|
||||
{0,0}
|
||||
};
|
||||
|
@@ -70,6 +70,7 @@ const luaL_Reg PlayerMetaRef::methods[] = {
|
||||
luamethod(MetaDataRef, set_int),
|
||||
luamethod(MetaDataRef, get_float),
|
||||
luamethod(MetaDataRef, set_float),
|
||||
luamethod(MetaDataRef, get_keys),
|
||||
luamethod(MetaDataRef, to_table),
|
||||
luamethod(MetaDataRef, from_table),
|
||||
luamethod(MetaDataRef, equals),
|
||||
|
@@ -74,6 +74,7 @@ const luaL_Reg StorageRef::methods[] = {
|
||||
luamethod(MetaDataRef, set_int),
|
||||
luamethod(MetaDataRef, get_float),
|
||||
luamethod(MetaDataRef, set_float),
|
||||
luamethod(MetaDataRef, get_keys),
|
||||
luamethod(MetaDataRef, to_table),
|
||||
luamethod(MetaDataRef, from_table),
|
||||
luamethod(MetaDataRef, equals),
|
||||
|
Reference in New Issue
Block a user