mirror of
https://github.com/BelfrySCAD/BOSL2.git
synced 2025-01-01 09:49:45 +00:00
Added ability to return default value from struct_val() if keyword is not present
This commit is contained in:
parent
22836c999c
commit
4cda1bf488
1 changed files with 5 additions and 4 deletions
|
@ -64,16 +64,17 @@ function struct_remove(struct, keyword) =
|
||||||
|
|
||||||
// Function: struct_val()
|
// Function: struct_val()
|
||||||
// Usage:
|
// Usage:
|
||||||
// struct_val(struct,keyword)
|
// struct_val(struct, keyword, default)
|
||||||
// Description:
|
// Description:
|
||||||
// Returns the value for the specified keyword in the structure, or undef if the keyword is not present
|
// Returns the value for the specified keyword in the structure, or default value if the keyword is not present
|
||||||
// Arguments:
|
// Arguments:
|
||||||
// struct = input structure
|
// struct = input structure
|
||||||
// keyword = keyword whose value to return
|
// keyword = keyword whose value to return
|
||||||
function struct_val(struct,keyword) =
|
// default = default value to return if keyword is not present, defaults to undef
|
||||||
|
function struct_val(struct, keyword, default=undef) =
|
||||||
assert(is_def(keyword),"keyword is missing")
|
assert(is_def(keyword),"keyword is missing")
|
||||||
let(ind = search([keyword],struct)[0])
|
let(ind = search([keyword],struct)[0])
|
||||||
ind == [] ? undef : struct[ind][1];
|
ind == [] ? default : struct[ind][1];
|
||||||
|
|
||||||
|
|
||||||
// Function: struct_keys()
|
// Function: struct_keys()
|
||||||
|
|
Loading…
Reference in a new issue