Hello, I am trying to extend nonposArgs to include more checks and I am having a hard time. I have gotten basic checks working, but I am not able to get some of the more complicated checks working. The tutorial shows that the syntax for extending nonposArgs is: *someobject|someclass* *proc|instproc* methodName {?optional arguments? argName args} { ... } I have not been able to get the ?optional arguments? to work. Example: I am trying to get some checks done that will check for specific values of the Arg. I would like to be able to pass those values into the check. xotcl::nonposArgs proc RANGE {allowedRange argName args} { .....code to verify the range } The syntax to use this would be similar to: Class Foo Foo instproc setMtu {{-mtu:RANGE 54-65535 "1500"}} {} { .... } This is similar to what Giovannni Cristelli asked in the post titled XOTcl extending nonPosArgs class from November 2004. Is there any way to do this currently? I am trying to replace a bloated package that is currently being used which has many of these checks available. I have tried many combinations of syntax to get this to work and have not been able to figure it out. Thanks, Shawn
Dear Shawn,
The tutorial shows that the syntax for extending nonposArgs is:
/someobject|someclass/ *proc|instproc* methodName {?optional arguments? argName args} { ... }
actually, this should read most probably .... ?optional nonpositional arguments? ...
For the time being, define an "argument type" named "mtu" as in:
xotcl::nonposArgs proc mtu {{-from 54} {-to 65535} name value} { if {$value < $from || $value > $to} { error "invalid argument $name: $value is not between $from and $to" } }
Class Foo Foo instproc setMtu {{-mtu:mtu "1500"}} {} { puts "setMtu mtu=$mtu" }
Foo f f setMtu -mtu 66 f setMtu -mtu 66999
Alternatively, one can use forward to be a little more generic, but still defining an own type mtu:
xotcl::nonposArgs forward mtu %self RANGE 43 65553 xotcl::nonposArgs proc RANGE {from to name value} { if {$value < $from || $value > $to} { error "invalid argument $name: $value is not between $from and $to" } }
Hope, this is acceptable for now. -gustaf