'\"
|
'\"
|
'\" Copyright (c) 1993-1998 Lucent Technologies, Inc.
|
'\" Copyright (c) 1993-1998 Lucent Technologies, Inc.
|
'\"
|
'\"
|
'\" See the file "license.terms" for information on usage and redistribution
|
'\" See the file "license.terms" for information on usage and redistribution
|
'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
|
'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
|
'\"
|
'\"
|
'\" RCS: $Id: local.n,v 1.1.1.1 2002-01-16 10:24:46 markom Exp $
|
'\" RCS: $Id: local.n,v 1.1.1.1 2002-01-16 10:24:46 markom Exp $
|
'\"
|
'\"
|
.so man.macros
|
.so man.macros
|
.TH local n "" itcl "[incr\ Tcl]"
|
.TH local n "" itcl "[incr\ Tcl]"
|
.BS
|
.BS
|
'\" Note: do not modify the .SH NAME line immediately below!
|
'\" Note: do not modify the .SH NAME line immediately below!
|
.SH NAME
|
.SH NAME
|
local \- create an object local to a procedure
|
local \- create an object local to a procedure
|
.SH SYNOPSIS
|
.SH SYNOPSIS
|
\fBlocal \fIclassName objName\fR ?\fIarg arg ...\fR?
|
\fBlocal \fIclassName objName\fR ?\fIarg arg ...\fR?
|
.BE
|
.BE
|
|
|
.SH DESCRIPTION
|
.SH DESCRIPTION
|
.PP
|
.PP
|
The \fBlocal\fR command creates an \fB[incr\ Tcl]\fR object that
|
The \fBlocal\fR command creates an \fB[incr\ Tcl]\fR object that
|
is local to the current call frame. When the call frame goes away,
|
is local to the current call frame. When the call frame goes away,
|
the object is automatically deleted. This command is useful for
|
the object is automatically deleted. This command is useful for
|
creating objects that are local to a procedure.
|
creating objects that are local to a procedure.
|
.PP
|
.PP
|
As a side effect, this command creates a variable named
|
As a side effect, this command creates a variable named
|
"\fCitcl-local-\fIxxx\fR", where \fIxxx\fR is the name of
|
"\fCitcl-local-\fIxxx\fR", where \fIxxx\fR is the name of
|
the object that is created. This variable detects when the
|
the object that is created. This variable detects when the
|
call frame is destroyed and automatically deletes the
|
call frame is destroyed and automatically deletes the
|
associated object.
|
associated object.
|
|
|
.SH EXAMPLE
|
.SH EXAMPLE
|
In the following example, a simple "counter" object is used
|
In the following example, a simple "counter" object is used
|
within the procedure "test". The counter is created as a
|
within the procedure "test". The counter is created as a
|
local object, so it is automatically deleted each time the
|
local object, so it is automatically deleted each time the
|
procedure exits. The \fBputs\fR statements included in the
|
procedure exits. The \fBputs\fR statements included in the
|
constructor/destructor show the object coming and going
|
constructor/destructor show the object coming and going
|
as the procedure is called.
|
as the procedure is called.
|
.CS
|
.CS
|
class counter {
|
class counter {
|
private variable count 0
|
private variable count 0
|
constructor {} {
|
constructor {} {
|
puts "created: $this"
|
puts "created: $this"
|
}
|
}
|
destructor {
|
destructor {
|
puts "deleted: $this"
|
puts "deleted: $this"
|
}
|
}
|
|
|
method bump {{by 1}} {
|
method bump {{by 1}} {
|
incr count $by
|
incr count $by
|
}
|
}
|
method get {} {
|
method get {} {
|
return $count
|
return $count
|
}
|
}
|
}
|
}
|
|
|
proc test {val} {
|
proc test {val} {
|
local counter x
|
local counter x
|
for {set i 0} {$i < $val} {incr i} {
|
for {set i 0} {$i < $val} {incr i} {
|
x bump
|
x bump
|
}
|
}
|
return [x get]
|
return [x get]
|
}
|
}
|
|
|
set result [test 5]
|
set result [test 5]
|
puts "test: $result"
|
puts "test: $result"
|
|
|
set result [test 10]
|
set result [test 10]
|
puts "test: $result"
|
puts "test: $result"
|
|
|
puts "objects: [info objects]"
|
puts "objects: [info objects]"
|
.CE
|
.CE
|
|
|
.SH KEYWORDS
|
.SH KEYWORDS
|
class, object, procedure
|
class, object, procedure
|
|
|