diff options
Diffstat (limited to 'src/script/lua_api')
-rw-r--r-- | src/script/lua_api/l_itemstackmeta.cpp | 1 | ||||
-rw-r--r-- | src/script/lua_api/l_metadata.cpp | 26 | ||||
-rw-r--r-- | src/script/lua_api/l_metadata.h | 3 | ||||
-rw-r--r-- | src/script/lua_api/l_nodemeta.cpp | 2 | ||||
-rw-r--r-- | src/script/lua_api/l_playermeta.cpp | 1 | ||||
-rw-r--r-- | src/script/lua_api/l_storage.cpp | 1 |
6 files changed, 34 insertions, 0 deletions
diff --git a/src/script/lua_api/l_itemstackmeta.cpp b/src/script/lua_api/l_itemstackmeta.cpp index 3c0f68406..8ce9673db 100644 --- a/src/script/lua_api/l_itemstackmeta.cpp +++ b/src/script/lua_api/l_itemstackmeta.cpp @@ -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), diff --git a/src/script/lua_api/l_metadata.cpp b/src/script/lua_api/l_metadata.cpp index 8388bc089..68b79331b 100644 --- a/src/script/lua_api/l_metadata.cpp +++ b/src/script/lua_api/l_metadata.cpp @@ -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) { diff --git a/src/script/lua_api/l_metadata.h b/src/script/lua_api/l_metadata.h index 084b06c83..cae15e232 100644 --- a/src/script/lua_api/l_metadata.h +++ b/src/script/lua_api/l_metadata.h @@ -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); diff --git a/src/script/lua_api/l_nodemeta.cpp b/src/script/lua_api/l_nodemeta.cpp index 3cfb25883..f4edc1790 100644 --- a/src/script/lua_api/l_nodemeta.cpp +++ b/src/script/lua_api/l_nodemeta.cpp @@ -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} }; diff --git a/src/script/lua_api/l_playermeta.cpp b/src/script/lua_api/l_playermeta.cpp index 6ccb53e1c..def65a1cc 100644 --- a/src/script/lua_api/l_playermeta.cpp +++ b/src/script/lua_api/l_playermeta.cpp @@ -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), diff --git a/src/script/lua_api/l_storage.cpp b/src/script/lua_api/l_storage.cpp index 4b3863ca9..e1d47ba72 100644 --- a/src/script/lua_api/l_storage.cpp +++ b/src/script/lua_api/l_storage.cpp @@ -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), |