forked from Mirrorlandia_minetest/minetest
Exception handling in Lua setting get
This commit is contained in:
parent
234bf99743
commit
57a2bd056c
@ -1316,7 +1316,8 @@ minetest.register_on_respawnplayer(function(player)
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
-- Example setting get
|
-- Example setting get
|
||||||
print("max_users = " .. dump(minetest.setting_get("max_users")))
|
print("setting max_users = " .. dump(minetest.setting_get("max_users")))
|
||||||
|
print("setting asdf = " .. dump(minetest.setting_get("asdf")))
|
||||||
|
|
||||||
--
|
--
|
||||||
-- Done, print some random stuff
|
-- Done, print some random stuff
|
||||||
|
@ -861,8 +861,12 @@ static int l_register_on_respawnplayer(lua_State *L)
|
|||||||
static int l_setting_get(lua_State *L)
|
static int l_setting_get(lua_State *L)
|
||||||
{
|
{
|
||||||
const char *name = luaL_checkstring(L, 1);
|
const char *name = luaL_checkstring(L, 1);
|
||||||
std::string value = g_settings->get(name);
|
try{
|
||||||
lua_pushstring(L, value.c_str());
|
std::string value = g_settings->get(name);
|
||||||
|
lua_pushstring(L, value.c_str());
|
||||||
|
} catch(SettingNotFoundException &e){
|
||||||
|
lua_pushnil(L);
|
||||||
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -870,8 +874,12 @@ static int l_setting_get(lua_State *L)
|
|||||||
static int l_setting_getbool(lua_State *L)
|
static int l_setting_getbool(lua_State *L)
|
||||||
{
|
{
|
||||||
const char *name = luaL_checkstring(L, 1);
|
const char *name = luaL_checkstring(L, 1);
|
||||||
bool value = g_settings->getBool(name);
|
try{
|
||||||
lua_pushboolean(L, value);
|
bool value = g_settings->getBool(name);
|
||||||
|
lua_pushboolean(L, value);
|
||||||
|
} catch(SettingNotFoundException &e){
|
||||||
|
lua_pushnil(L);
|
||||||
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user