For Programmers: Free Programming Magazines  


Home > Archive > Tcl > May 2006 > Re: snit newbie









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: snit newbie
arlie

2006-05-25, 10:03 pm

#=======================================
========================================
=#
package require snit

#=======================================
========================================
=#
snit::type dog {
delegate method wag to mytail
delegate method xvar to myvarhandler

option -silly "something silly!"

variable max 100

constructor {args} {
install mytail using tail %AUTO% -partof $self
install myvarhandler using varhandler %AUTO% -partof
$self
$self configurelist $args
}

method test {} { return "test"}

method var { args } {
# Save previous value of variable
set temp ""
set var_xpr "set temp \"$[lindex $args 0]\""
eval $var_xpr

# If there is 2nd argument then set value of variable to 2nd
argument
if { [llength $args] > 1 } {
set var_xpr "set [lindex $args 0] \"[lindex $args 1]\""
eval $var_xpr
}

return $temp
}
}

#=======================================
========================================
=#
snit::type tail {
constructor {args} {puts "Tail create!"}
method wag {} { return "Wag, wag, wag."}
}

#=======================================
========================================
=#
snit::type varhandler {
constructor {args} {}

method xvar { args } {
# Save previous value of variable
set temp ""
set var_xpr "set temp \"$[lindex $args 0]\""
eval $var_xpr

# If there is 2nd argument then set value of variable to 2nd
argument
if { [llength $args] > 1 } {
set var_xpr "set [lindex $args 0] \"[lindex $args 1]\""
eval $var_xpr
}

return $temp
}
}

////////////////////////////////////////////////////////////////////////

(snit-practice) 2 % puppy var max
100
(snit-practice) 3 % puppy xvar max
can't read "max": no such variable

////////////////////////////////////////////////////////////////////////

Is there a way I can give "xvar" method access to my variables in
type/class "dog"?

Regards,

Arlie L.C.

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com