Skip to content

Commit

Permalink
Allow 'default' parameter in 'settings:get_bool' function
Browse files Browse the repository at this point in the history
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
  • Loading branch information
AntumDeluge authored and rubenwardy committed Dec 17, 2017
1 parent 26c7e98 commit 18b9210
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 3 additions & 1 deletion doc/lua_api.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4131,7 +4131,9 @@ It can be created via `Settings(filename)`.

#### Methods
* `get(key)`: returns a value
* `get_bool(key)`: returns a boolean
* `get_bool(key, [default])`: returns a boolean
* `default` is the value returned if `key` is not found.
* Returns `nil` if `key` is not found and `default` not specified.
* `get_np_group(key)`: returns a NoiseParams table
* `set(key, value)`
* Setting names can't contain whitespace or any of `="{}#`.
Expand Down
6 changes: 5 additions & 1 deletion src/script/lua_api/l_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,11 @@ int LuaSettings::l_get_bool(lua_State* L)
bool value = o->m_settings->getBool(key);
lua_pushboolean(L, value);
} else {
lua_pushnil(L);
// Push default value
if (lua_isboolean(L, 3))
lua_pushboolean(L, lua_toboolean(L, 3));
else
lua_pushnil(L);
}

return 1;
Expand Down

0 comments on commit 18b9210

Please sign in to comment.