summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPerttu Ahola <celeron55@gmail.com>2011-11-26 03:40:16 +0200
committerPerttu Ahola <celeron55@gmail.com>2011-11-29 19:13:53 +0200
commit57a2bd056c6c0e61cd26490a2ca653f5720d60ea (patch)
tree4d82f62488f142607b466b40db94c202694d5c72 /src
parent234bf99743f65d4005673defd65aa3e96ddb853f (diff)
downloadminetest-57a2bd056c6c0e61cd26490a2ca653f5720d60ea.tar.gz
minetest-57a2bd056c6c0e61cd26490a2ca653f5720d60ea.tar.bz2
minetest-57a2bd056c6c0e61cd26490a2ca653f5720d60ea.zip
Exception handling in Lua setting get
Diffstat (limited to 'src')
-rw-r--r--src/scriptapi.cpp16
1 files changed, 12 insertions, 4 deletions
diff --git a/src/scriptapi.cpp b/src/scriptapi.cpp
index f1f0658f4..af6e1779f 100644
--- a/src/scriptapi.cpp
+++ b/src/scriptapi.cpp
@@ -861,8 +861,12 @@ static int l_register_on_respawnplayer(lua_State *L)
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());
+ try{
+ std::string value = g_settings->get(name);
+ lua_pushstring(L, value.c_str());
+ } catch(SettingNotFoundException &e){
+ lua_pushnil(L);
+ }
return 1;
}
@@ -870,8 +874,12 @@ static int l_setting_get(lua_State *L)
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);
+ try{
+ bool value = g_settings->getBool(name);
+ lua_pushboolean(L, value);
+ } catch(SettingNotFoundException &e){
+ lua_pushnil(L);
+ }
return 1;
}