diff options
author | mescalinum <mescalinum@users.sourceforge.net> | 2009-08-31 13:42:50 +0000 |
---|---|---|
committer | mescalinum <mescalinum@users.sourceforge.net> | 2009-08-31 13:42:50 +0000 |
commit | 5cfef34ec9fc67df3149436a83873ce527d4af9d (patch) | |
tree | 880033ba25f8e1f8de5ca5e7b48dab56f980b666 /pdlib.tcl | |
parent | aa048d93e8fdae5b8152b3c963da02b3cd244274 (diff) |
add usage examples and help
svn path=/trunk/externals/tclpd/; revision=12154
Diffstat (limited to 'pdlib.tcl')
-rw-r--r-- | pdlib.tcl | 45 |
1 files changed, 19 insertions, 26 deletions
@@ -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 + } } - } |