scaddy/preconditions.scad
Tony Tkacik 34fb5c964c Resync
Signed-off-by: Tony Tkacik <tonydamage@gmail.com>
2019-02-23 20:26:02 +01:00

23 lines
680 B
OpenSCAD

use <./base.scad>;
ERROR_BEGIN="<font color='red'>";
ERROR_END="</font>";
module precondition(test,error,m=undef) {
if(!test) {
echo(str(ERROR_BEGIN,default(m,parent_module(1)),": ",error,ERROR_END));
assert(false);
} else children();
}
function precondition(test,value,error)=test ? value : echo(str(ERROR_BEGIN,error,ERROR_END)) assert(false);
module check_defined(val,error,m=undef) {
precondition(val != undef,error) children();
}
function check_defined(value,error)=precondition(value != undef,error);
module check_parent(parent,statement,error,m=undef) {
precondition(parent_module(3) == parent,str(statement,"(): ",error)) children();
}