[Xotcl] poll for opinions
Zoran Vasiljevic
zoran@archiware.com
Thu, 21 Feb 2002 19:46:30 +0100
On Thursday 21 February 2002 18:17, Zoran Vasiljevic wrote:
>
> Class foo
> foo instproc init {args} {
> puts stderr "[self] comming"
> next
> }
> foo instproc destroy {args} {
> puts stderr "[self] leaving"
> next
> }
> foo instproc test {args} {
> puts "Hallo World"
> }
> proc dummy {args} {
> foo private fooVar ; # "private" might be a new constructor method
> $fooVar test
> return
> }
>
> When somebody calls "dummy" proc, a new "foo" object gets created
> (the "private" method" and automatically destroyed when proc returns.
> Can such thing be done with simple Tcl variable traces, hm?
>
>
Hm, what about this little baby:
proc ::xotcl::gc {name1 name2 op} {
::uplevel $name1 destroy
}
Class instproc private {varname args} {
::upvar $varname v
::set v $varname
::uplevel trace variable $varname u ::xotcl::gc
::eval [self] create $varname $args
}
Yields...
% Class foo
% foo private bar
% $bar
wrong # args: should be {bar message ?args...?}
% set bar
::bar
% unset bar
% ::bar
invalid command name "::bar"
Cheer's
Zoran