mirror of
https://github.com/BelfrySCAD/BOSL2.git
synced 2025-01-15 17:09:40 +00:00
Merge ae6e830edb
into 8383d360cc
This commit is contained in:
commit
ae21fc567e
2 changed files with 8 additions and 1 deletions
|
@ -50,7 +50,10 @@ function struct_set(struct, key, value, grow=true) =
|
||||||
:
|
:
|
||||||
assert(is_list(key) && len(key)%2==0, "[key,value] pair list is not a list or has an odd length")
|
assert(is_list(key) && len(key)%2==0, "[key,value] pair list is not a list or has an odd length")
|
||||||
let(
|
let(
|
||||||
new_entries = [for(i=[0:1:len(key)/2-1]) [key[2*i], key[2*i+1]]],
|
new_entries = [for(i=[0:1:len(key)/2-1]) if (is_def(key[2*i+1])) [key[2*i], key[2*i+1]]]
|
||||||
|
)
|
||||||
|
len(new_entries) == 0 ? struct :
|
||||||
|
let(
|
||||||
newkeys = column(new_entries,0),
|
newkeys = column(new_entries,0),
|
||||||
indlist = search(newkeys, struct,0,0),
|
indlist = search(newkeys, struct,0,0),
|
||||||
badkeys = grow ? (search([undef],new_entries,1,0)[0] != [] ? [undef] : [])
|
badkeys = grow ? (search([undef],new_entries,1,0)[0] != [] ? [undef] : [])
|
||||||
|
|
|
@ -19,6 +19,10 @@ module test_struct_set() {
|
||||||
assert(st7 == [["Bar", 28],["Foo",91],[3,4],[[5,7],99]]);
|
assert(st7 == [["Bar", 28],["Foo",91],[3,4],[[5,7],99]]);
|
||||||
st8 = struct_set(st3,[]);
|
st8 = struct_set(st3,[]);
|
||||||
assert(st8==st3);
|
assert(st8==st3);
|
||||||
|
st9 = struct_set(st2, ["Baz", undef]);
|
||||||
|
assert(st9 == st2);
|
||||||
|
st10 = struct_set(st2, ["Foo", 91, "Baz", undef]);
|
||||||
|
assert(st10 == st3);
|
||||||
}
|
}
|
||||||
test_struct_set();
|
test_struct_set();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue