diff options
author | Perttu Ahola <celeron55@gmail.com> | 2011-11-26 03:37:09 +0200 |
---|---|---|
committer | Perttu Ahola <celeron55@gmail.com> | 2011-11-29 19:13:53 +0200 |
commit | 234bf99743f65d4005673defd65aa3e96ddb853f (patch) | |
tree | 55496c5de0c18f91970e2ca7385b9767b1c0dc66 /src | |
parent | f93144fee7093d19eb7f99bbb5068ab2e704c8ed (diff) | |
download | minetest-234bf99743f65d4005673defd65aa3e96ddb853f.tar.gz minetest-234bf99743f65d4005673defd65aa3e96ddb853f.tar.bz2 minetest-234bf99743f65d4005673defd65aa3e96ddb853f.zip |
Lua setting getter
Diffstat (limited to 'src')
-rw-r--r-- | src/scriptapi.cpp | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/scriptapi.cpp b/src/scriptapi.cpp index 03bdd3a7d..f1f0658f4 100644 --- a/src/scriptapi.cpp +++ b/src/scriptapi.cpp @@ -38,6 +38,8 @@ extern "C" { #include "tooldef.h" #include "nodedef.h" #include "craftdef.h" +#include "main.h" // For g_settings +#include "settings.h" // For accessing g_settings /* TODO: @@ -855,6 +857,24 @@ static int l_register_on_respawnplayer(lua_State *L) return register_lua_callback(L, "registered_on_respawnplayers"); } +// setting_get(name) +static int l_setting_get(lua_State *L) +{ + const char *name = luaL_checkstring(L, 1); + std::string value = g_settings->get(name); + lua_pushstring(L, value.c_str()); + return 1; +} + +// setting_getbool(name) +static int l_setting_getbool(lua_State *L) +{ + const char *name = luaL_checkstring(L, 1); + bool value = g_settings->getBool(name); + lua_pushboolean(L, value); + return 1; +} + static const struct luaL_Reg minetest_f [] = { {"register_nodedef_defaults", l_register_nodedef_defaults}, {"register_entity", l_register_entity}, @@ -867,6 +887,8 @@ static const struct luaL_Reg minetest_f [] = { {"register_on_punchnode", l_register_on_punchnode}, {"register_on_newplayer", l_register_on_newplayer}, {"register_on_respawnplayer", l_register_on_respawnplayer}, + {"setting_get", l_setting_get}, + {"setting_getbool", l_setting_getbool}, {NULL, NULL} }; |