diff options
author | SmallJoker <mk939@ymail.com> | 2021-01-20 16:58:59 +0100 |
---|---|---|
committer | sfan5 <sfan5@live.de> | 2021-03-01 12:14:41 +0100 |
commit | 3a2f55bc19bec1cb3f76d0edc30208a1eff11925 (patch) | |
tree | 66128fa22316df01fefb8b7b02d6bef0e36125ca /src/script/lua_api | |
parent | c401a06f8a669d1fd4194010ccf23d7043d70fb1 (diff) | |
download | minetest-3a2f55bc19bec1cb3f76d0edc30208a1eff11925.tar.gz minetest-3a2f55bc19bec1cb3f76d0edc30208a1eff11925.tar.bz2 minetest-3a2f55bc19bec1cb3f76d0edc30208a1eff11925.zip |
Settings: Push groups in to_table as well
Diffstat (limited to 'src/script/lua_api')
-rw-r--r-- | src/script/lua_api/l_settings.cpp | 33 |
1 files changed, 25 insertions, 8 deletions
diff --git a/src/script/lua_api/l_settings.cpp b/src/script/lua_api/l_settings.cpp index bcbaf15fa..85df8ab34 100644 --- a/src/script/lua_api/l_settings.cpp +++ b/src/script/lua_api/l_settings.cpp @@ -20,6 +20,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "lua_api/l_settings.h" #include "lua_api/l_internal.h" #include "cpp_api/s_security.h" +#include "threading/mutex_auto_lock.h" #include "util/string.h" // FlagDesc #include "settings.h" #include "noise.h" @@ -253,20 +254,36 @@ int LuaSettings::l_write(lua_State* L) return 1; } -// to_table(self) -> {[key1]=value1,...} -int LuaSettings::l_to_table(lua_State* L) +static void push_settings_table(lua_State *L, const Settings *settings) { - NO_MAP_LOCK_REQUIRED; - LuaSettings* o = checkobject(L, 1); - - std::vector<std::string> keys = o->m_settings->getNames(); - + std::vector<std::string> keys = settings->getNames(); lua_newtable(L); for (const std::string &key : keys) { - lua_pushstring(L, o->m_settings->get(key).c_str()); + std::string value; + Settings *group = nullptr; + + if (settings->getNoEx(key, value)) { + lua_pushstring(L, value.c_str()); + } else if (settings->getGroupNoEx(key, group)) { + // Recursively push tables + push_settings_table(L, group); + } else { + // Impossible case (multithreading) due to MutexAutoLock + continue; + } + lua_setfield(L, -2, key.c_str()); } +} + +// to_table(self) -> {[key1]=value1,...} +int LuaSettings::l_to_table(lua_State* L) +{ + NO_MAP_LOCK_REQUIRED; + LuaSettings* o = checkobject(L, 1); + MutexAutoLock(o->m_settings->m_mutex); + push_settings_table(L, o->m_settings); return 1; } |