aboutsummaryrefslogtreecommitdiff
path: root/src/script/lua_api
diff options
context:
space:
mode:
authorSmallJoker <SmallJoker@users.noreply.github.com>2020-01-25 16:56:54 +0100
committerGitHub <noreply@github.com>2020-01-25 16:56:54 +0100
commitcde2a7f6f24f638421238ead4e61b155322fefc8 (patch)
tree96b6b1dd00a0c14660eea6f3f518b5d832dc1bd8 /src/script/lua_api
parent9cb3219f34be983e1b84a62a64c25e137d587365 (diff)
downloadminetest-cde2a7f6f24f638421238ead4e61b155322fefc8.tar.gz
minetest-cde2a7f6f24f638421238ead4e61b155322fefc8.tar.bz2
minetest-cde2a7f6f24f638421238ead4e61b155322fefc8.zip
Settings: Add get_flags API for mapgen flags (mg_flags, mgv6_spflags, ...) (#9284)
Unified flags handling in C++ and Lua Settings API -> Reading only, for now. Writing can be implemented later, if needed. API function to read the currently active flags -> was impossible from Lua Co-authored-by: Wuzzy <wuzzy2@mail.ru>
Diffstat (limited to 'src/script/lua_api')
-rw-r--r--src/script/lua_api/l_settings.cpp25
-rw-r--r--src/script/lua_api/l_settings.h3
2 files changed, 28 insertions, 0 deletions
diff --git a/src/script/lua_api/l_settings.cpp b/src/script/lua_api/l_settings.cpp
index cc2c73789..33eb02392 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 "util/string.h" // FlagDesc
#include "settings.h"
#include "noise.h"
#include "log.h"
@@ -128,6 +129,29 @@ int LuaSettings::l_get_np_group(lua_State *L)
return 1;
}
+int LuaSettings::l_get_flags(lua_State *L)
+{
+ NO_MAP_LOCK_REQUIRED;
+ LuaSettings *o = checkobject(L, 1);
+ std::string key = std::string(luaL_checkstring(L, 2));
+
+ u32 flags = 0;
+ auto flagdesc = o->m_settings->getFlagDescFallback(key);
+ if (o->m_settings->getFlagStrNoEx(key, flags, flagdesc)) {
+ lua_newtable(L);
+ int table = lua_gettop(L);
+ for (size_t i = 0; flagdesc[i].name; ++i) {
+ lua_pushboolean(L, flags & flagdesc[i].flag);
+ lua_setfield(L, table, flagdesc[i].name);
+ }
+ lua_pushvalue(L, table);
+ } else {
+ lua_pushnil(L);
+ }
+
+ return 1;
+}
+
// set(self, key, value)
int LuaSettings::l_set(lua_State* L)
{
@@ -305,6 +329,7 @@ const luaL_Reg LuaSettings::methods[] = {
luamethod(LuaSettings, get),
luamethod(LuaSettings, get_bool),
luamethod(LuaSettings, get_np_group),
+ luamethod(LuaSettings, get_flags),
luamethod(LuaSettings, set),
luamethod(LuaSettings, set_bool),
luamethod(LuaSettings, set_np_group),
diff --git a/src/script/lua_api/l_settings.h b/src/script/lua_api/l_settings.h
index dcf39a89e..67d7b342b 100644
--- a/src/script/lua_api/l_settings.h
+++ b/src/script/lua_api/l_settings.h
@@ -42,6 +42,9 @@ private:
// get_np_group(self, key) -> noiseparam
static int l_get_np_group(lua_State *L);
+ // get_flags(self, key) -> key/value table
+ static int l_get_flags(lua_State *L);
+
// set(self, key, value)
static int l_set(lua_State *L);