Skip to content

Commit 18b9210

Browse files
AntumDelugerubenwardy
authored andcommittedDec 17, 2017
Allow 'default' parameter in 'settings:get_bool' function
Default value is used when the setting key is not found in the config file. If default value is not set, 'nil' is returned. #6188
1 parent 26c7e98 commit 18b9210

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed
 

‎doc/lua_api.txt

+3-1
Original file line numberDiff line numberDiff line change
@@ -4131,7 +4131,9 @@ It can be created via `Settings(filename)`.
41314131

41324132
#### Methods
41334133
* `get(key)`: returns a value
4134-
* `get_bool(key)`: returns a boolean
4134+
* `get_bool(key, [default])`: returns a boolean
4135+
* `default` is the value returned if `key` is not found.
4136+
* Returns `nil` if `key` is not found and `default` not specified.
41354137
* `get_np_group(key)`: returns a NoiseParams table
41364138
* `set(key, value)`
41374139
* Setting names can't contain whitespace or any of `="{}#`.

‎src/script/lua_api/l_settings.cpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,11 @@ int LuaSettings::l_get_bool(lua_State* L)
100100
bool value = o->m_settings->getBool(key);
101101
lua_pushboolean(L, value);
102102
} else {
103-
lua_pushnil(L);
103+
// Push default value
104+
if (lua_isboolean(L, 3))
105+
lua_pushboolean(L, lua_toboolean(L, 3));
106+
else
107+
lua_pushnil(L);
104108
}
105109

106110
return 1;

0 commit comments

Comments
 (0)
Please sign in to comment.