aboutsummaryrefslogtreecommitdiff
path: root/src/script/lua_api
diff options
context:
space:
mode:
Diffstat (limited to 'src/script/lua_api')
-rw-r--r--src/script/lua_api/l_settings.cpp38
-rw-r--r--src/script/lua_api/l_settings.h7
2 files changed, 45 insertions, 0 deletions
diff --git a/src/script/lua_api/l_settings.cpp b/src/script/lua_api/l_settings.cpp
index 2d6769ea1..141ac61d1 100644
--- a/src/script/lua_api/l_settings.cpp
+++ b/src/script/lua_api/l_settings.cpp
@@ -21,6 +21,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "lua_api/l_internal.h"
#include "cpp_api/s_security.h"
#include "settings.h"
+#include "noise.h"
#include "log.h"
@@ -105,6 +106,24 @@ int LuaSettings::l_get_bool(lua_State* L)
return 1;
}
+// get_np_group(self, key) -> value
+int LuaSettings::l_get_np_group(lua_State *L)
+{
+ NO_MAP_LOCK_REQUIRED;
+ LuaSettings *o = checkobject(L, 1);
+
+ std::string key = std::string(luaL_checkstring(L, 2));
+ if (o->m_settings->exists(key)) {
+ NoiseParams np;
+ o->m_settings->getNoiseParams(key, np);
+ push_noiseparams(L, &np);
+ } else {
+ lua_pushnil(L);
+ }
+
+ return 1;
+}
+
// set(self, key, value)
int LuaSettings::l_set(lua_State* L)
{
@@ -138,6 +157,23 @@ int LuaSettings::l_set_bool(lua_State* L)
return 1;
}
+// set(self, key, value)
+int LuaSettings::l_set_np_group(lua_State *L)
+{
+ NO_MAP_LOCK_REQUIRED;
+ LuaSettings *o = checkobject(L, 1);
+
+ std::string key = std::string(luaL_checkstring(L, 2));
+ NoiseParams value;
+ read_noiseparams(L, 3, &value);
+
+ SET_SECURITY_CHECK(L, key);
+
+ o->m_settings->setNoiseParams(key, value, false);
+
+ return 0;
+}
+
// remove(self, key) -> success
int LuaSettings::l_remove(lua_State* L)
{
@@ -264,8 +300,10 @@ const char LuaSettings::className[] = "Settings";
const luaL_Reg LuaSettings::methods[] = {
luamethod(LuaSettings, get),
luamethod(LuaSettings, get_bool),
+ luamethod(LuaSettings, get_np_group),
luamethod(LuaSettings, set),
luamethod(LuaSettings, set_bool),
+ luamethod(LuaSettings, set_np_group),
luamethod(LuaSettings, remove),
luamethod(LuaSettings, get_names),
luamethod(LuaSettings, write),
diff --git a/src/script/lua_api/l_settings.h b/src/script/lua_api/l_settings.h
index 500917f0a..dcf39a89e 100644
--- a/src/script/lua_api/l_settings.h
+++ b/src/script/lua_api/l_settings.h
@@ -19,6 +19,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#pragma once
+#include "common/c_content.h"
#include "lua_api/l_base.h"
class Settings;
@@ -38,12 +39,18 @@ private:
// get_bool(self, key) -> boolean
static int l_get_bool(lua_State *L);
+ // get_np_group(self, key) -> noiseparam
+ static int l_get_np_group(lua_State *L);
+
// set(self, key, value)
static int l_set(lua_State *L);
// set_bool(self, key, value)
static int l_set_bool(lua_State *L);
+ // set_np_group(self, key, value)
+ static int l_set_np_group(lua_State *L);
+
// remove(self, key) -> success
static int l_remove(lua_State *L);