View · Search · Index
No registered users in community xowiki
in last 10 minutes

Re: [Xotcl] Extending nonposArgs in XOTcl

From: Gustaf Neumann <neumann_at_wu-wien.ac.at>
Date: Wed, 26 Oct 2005 13:35:02 +0200

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