OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [insight/] [itcl/] [itcl/] [doc/] [local.n] - Blame information for rev 1773

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 578 markom
'\"
2
'\" Copyright (c) 1993-1998  Lucent Technologies, Inc.
3
'\"
4
'\" See the file "license.terms" for information on usage and redistribution
5
'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
6
'\"
7
'\" RCS: $Id: local.n,v 1.1.1.1 2002-01-16 10:24:46 markom Exp $
8
'\"
9
.so man.macros
10
.TH local n "" itcl "[incr\ Tcl]"
11
.BS
12
'\" Note:  do not modify the .SH NAME line immediately below!
13
.SH NAME
14
local \- create an object local to a procedure
15
.SH SYNOPSIS
16
\fBlocal \fIclassName objName\fR ?\fIarg arg ...\fR?
17
.BE
18
 
19
.SH DESCRIPTION
20
.PP
21
The \fBlocal\fR command creates an \fB[incr\ Tcl]\fR object that
22
is local to the current call frame.  When the call frame goes away,
23
the object is automatically deleted.  This command is useful for
24
creating objects that are local to a procedure.
25
.PP
26
As a side effect, this command creates a variable named
27
"\fCitcl-local-\fIxxx\fR", where \fIxxx\fR is the name of
28
the object that is created.  This variable detects when the
29
call frame is destroyed and automatically deletes the
30
associated object.
31
 
32
.SH EXAMPLE
33
In the following example, a simple "counter" object is used
34
within the procedure "test".  The counter is created as a
35
local object, so it is automatically deleted each time the
36
procedure exits.  The \fBputs\fR statements included in the
37
constructor/destructor show the object coming and going
38
as the procedure is called.
39
.CS
40
class counter {
41
    private variable count 0
42
    constructor {} {
43
        puts "created: $this"
44
    }
45
    destructor {
46
        puts "deleted: $this"
47
    }
48
 
49
    method bump {{by 1}} {
50
        incr count $by
51
    }
52
    method get {} {
53
        return $count
54
    }
55
}
56
 
57
proc test {val} {
58
    local counter x
59
    for {set i 0} {$i < $val} {incr i} {
60
        x bump
61
    }
62
    return [x get]
63
}
64
 
65
set result [test 5]
66
puts "test: $result"
67
 
68
set result [test 10]
69
puts "test: $result"
70
 
71
puts "objects: [info objects]"
72
.CE
73
 
74
.SH KEYWORDS
75
class, object, procedure

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.