From 5cfef34ec9fc67df3149436a83873ce527d4af9d Mon Sep 17 00:00:00 2001 From: mescalinum Date: Mon, 31 Aug 2009 13:42:50 +0000 Subject: add usage examples and help svn path=/trunk/externals/tclpd/; revision=12154 --- pdlib.tcl | 45 +++++++++++++++++++-------------------------- 1 file changed, 19 insertions(+), 26 deletions(-) (limited to 'pdlib.tcl') diff --git a/pdlib.tcl b/pdlib.tcl index 29fe8b3..c349dfd 100644 --- a/pdlib.tcl +++ b/pdlib.tcl @@ -129,38 +129,31 @@ namespace eval ::pd { poststring2 [concat {*}$args] } - proc assert= {a b} { - if {$a != $b} { - post "ASSERTION FAILED: \"$a\" == \"$b\"" - return 0 - } - return 1 - } - proc args {} { return [uplevel 1 "llength \$args"] } - proc arg_float {n} { + proc arg {n {assertion any}} { set v [uplevel 1 "lindex \$args $n"] + set i 0 foreach {selector value} $v {break} - assert= $selector "float" - return $value - } - - proc arg_int {n} { - set v [uplevel 1 "lindex \$args $n"] - foreach {selector value} $v {break} - assert= $selector "float" - return [expr {int($value)}] - } - - proc arg_symbol {n} { - set v [uplevel 1 "lindex \$args $n"] - foreach {selector value} $v {break} - assert= $selector "symbol" - return $value + if {$assertion == {int}} { + set assertion {float} + set i 1 + } + if {$assertion != {any}} { + if {$selector != $assertion} { + return -code error "arg #$n is $selector, must be $assertion" + } + } + if {$assertion == {float} && $i && $value != int($value)} { + return -code error "arg #$n is float, must be int" + } + if {$assertion == {float} && $i} { + return [expr {int($value)}] + } else { + return $value + } } - } -- cgit v1.2.1