mirror of
https://github.com/BelfrySCAD/BOSL2.git
synced 2025-01-01 09:49:45 +00:00
Fixed structs.scad docs formatting. Fixed bug in is_struct().
This commit is contained in:
parent
892e98e773
commit
d20caf7d59
2 changed files with 73 additions and 59 deletions
50
structs.scad
50
structs.scad
|
@ -27,17 +27,19 @@
|
||||||
// that is also an error. If speed matters, use the first form with scalars rather than the list form: this is
|
// that is also an error. If speed matters, use the first form with scalars rather than the list form: this is
|
||||||
// about thirty times faster.
|
// about thirty times faster.
|
||||||
// Arguments:
|
// Arguments:
|
||||||
// struct = input structure
|
// struct = Input structure.
|
||||||
// keyword = keyword to set
|
// keyword = Keyword to set.
|
||||||
// value = value to set the keyword to
|
// value = Value to set the keyword to.
|
||||||
// grow = Set to true to allow structure to grow, or false for new keywords to generate an error. Default: true
|
// grow = Set to true to allow structure to grow, or false for new keywords to generate an error. Default: true
|
||||||
function struct_set(struct, keyword, value=undef, grow=true) =
|
function struct_set(struct, keyword, value=undef, grow=true) =
|
||||||
!is_list(keyword) ?
|
!is_list(keyword)? (
|
||||||
let( ind=search([keyword],struct,1,0)[0] )
|
let( ind=search([keyword],struct,1,0)[0] )
|
||||||
(ind==[] ? assert(grow,str("Unknown keyword \"",keyword))
|
ind==[]? (
|
||||||
concat(struct, [[keyword,value]]) :
|
assert(grow,str("Unknown keyword \"",keyword))
|
||||||
list_set(struct, [ind], [[keyword,value]])) :
|
concat(struct, [[keyword,value]])
|
||||||
_parse_pairs(struct,keyword,grow);
|
) : list_set(struct, [ind], [[keyword,value]])
|
||||||
|
) : _parse_pairs(struct,keyword,grow);
|
||||||
|
|
||||||
|
|
||||||
function _parse_pairs(spec, input, grow=true, index=0, result=undef) =
|
function _parse_pairs(spec, input, grow=true, index=0, result=undef) =
|
||||||
assert(len(input)%2==0,"Odd number of entries in [keyword,value] pair list")
|
assert(len(input)%2==0,"Odd number of entries in [keyword,value] pair list")
|
||||||
|
@ -45,6 +47,7 @@ function _parse_pairs(spec, input, grow=true, index=0, result=undef) =
|
||||||
index == len(input) ? result :
|
index == len(input) ? result :
|
||||||
_parse_pairs(spec,input,grow,index+2,struct_set(result, input[index], input[index+1],grow));
|
_parse_pairs(spec,input,grow,index+2,struct_set(result, input[index], input[index+1],grow));
|
||||||
|
|
||||||
|
|
||||||
// Function: struct_remove()
|
// Function: struct_remove()
|
||||||
// Usage:
|
// Usage:
|
||||||
// struct_remove(struct, keyword)
|
// struct_remove(struct, keyword)
|
||||||
|
@ -58,6 +61,7 @@ function struct_remove(struct, keyword) =
|
||||||
let(ind = search(keyword, struct))
|
let(ind = search(keyword, struct))
|
||||||
list_remove(struct, ind);
|
list_remove(struct, ind);
|
||||||
|
|
||||||
|
|
||||||
// Function: struct_val()
|
// Function: struct_val()
|
||||||
// Usage:
|
// Usage:
|
||||||
// struct_val(struct,keyword)
|
// struct_val(struct,keyword)
|
||||||
|
@ -71,9 +75,10 @@ function struct_val(struct,keyword) =
|
||||||
let(ind = search([keyword],struct)[0])
|
let(ind = search([keyword],struct)[0])
|
||||||
ind == [] ? undef : struct[ind][1];
|
ind == [] ? undef : struct[ind][1];
|
||||||
|
|
||||||
|
|
||||||
// Function: struct_keys()
|
// Function: struct_keys()
|
||||||
// Usage:
|
// Usage:
|
||||||
// struct_keys(struct)
|
// keys = struct_keys(struct)
|
||||||
// Description:
|
// Description:
|
||||||
// Returns a list of the keys in a structure
|
// Returns a list of the keys in a structure
|
||||||
// Arguments:
|
// Arguments:
|
||||||
|
@ -81,7 +86,8 @@ function struct_val(struct,keyword) =
|
||||||
function struct_keys(struct) =
|
function struct_keys(struct) =
|
||||||
[for(entry=struct) entry[0]];
|
[for(entry=struct) entry[0]];
|
||||||
|
|
||||||
// Function&Module struct_echo()
|
|
||||||
|
// Function&Module: struct_echo()
|
||||||
// Usage:
|
// Usage:
|
||||||
// struct_echo(struct, [name])
|
// struct_echo(struct, [name])
|
||||||
// Description:
|
// Description:
|
||||||
|
@ -98,13 +104,21 @@ module struct_echo(struct,name="") {
|
||||||
dummy = struct_echo(struct,name);
|
dummy = struct_echo(struct,name);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Function is_struct()
|
|
||||||
|
// Function: is_struct()
|
||||||
// Usage:
|
// Usage:
|
||||||
// is_struct(struct)
|
// is_struct(struct)
|
||||||
// Description: Returns true if the input has the form of a structure, false otherwise.
|
// Description:
|
||||||
function is_struct(struct, ind=0) =
|
// Returns true if the input has the form of a structure, false otherwise.
|
||||||
is_list(struct) && (
|
function is_struct(x) =
|
||||||
struct == [] ||
|
is_list(x) && [
|
||||||
let(dim = array_dim(struct))
|
for (xx=x) if(
|
||||||
len(dim)==2 && dim[1]==2
|
!is_list(xx) ||
|
||||||
);
|
len(xx) != 2 ||
|
||||||
|
!is_string(xx[0])
|
||||||
|
) 1
|
||||||
|
] == [];
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// vim: noexpandtab tabstop=4 shiftwidth=4 softtabstop=4 nowrap
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
BOSL_VERSION = [2,0,310];
|
BOSL_VERSION = [2,0,311];
|
||||||
|
|
||||||
|
|
||||||
// Section: BOSL Library Version Functions
|
// Section: BOSL Library Version Functions
|
||||||
|
|
Loading…
Reference in a new issue