diff options
| author | dkf <donal.k.fellows@manchester.ac.uk> | 2018-09-28 09:18:49 (GMT) |
|---|---|---|
| committer | dkf <donal.k.fellows@manchester.ac.uk> | 2018-09-28 09:18:49 (GMT) |
| commit | 9dabbdf40b10e3f0419d5ad5b96f4d7c3189bc6a (patch) | |
| tree | 233faf46a3a4bde6f5a4c5ad45db18d7e7cdd69e /doc/classvariable.n | |
| parent | 0d36d5f3d85b79ed2c3565112c78bbd18d1a7990 (diff) | |
| parent | 2f3fc1cfa29f6a4dac413ac62258bfb235feb257 (diff) | |
| download | tcl-9dabbdf40b10e3f0419d5ad5b96f4d7c3189bc6a.zip tcl-9dabbdf40b10e3f0419d5ad5b96f4d7c3189bc6a.tar.gz tcl-9dabbdf40b10e3f0419d5ad5b96f4d7c3189bc6a.tar.bz2 | |
merge core-8-branch
Diffstat (limited to 'doc/classvariable.n')
| -rw-r--r-- | doc/classvariable.n | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/doc/classvariable.n b/doc/classvariable.n new file mode 100644 index 0000000..0798bb2 --- /dev/null +++ b/doc/classvariable.n @@ -0,0 +1,78 @@ +'\" +'\" Copyright (c) 2011-2015 Andreas Kupries +'\" Copyright (c) 2018 Donal K. Fellows +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH classvariable n 0.3 TclOO "TclOO Commands" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +classvariable \- create link from local variable to variable in class +.SH SYNOPSIS +.nf +package require TclOO + +\fBclassvariable\fR \fIvariableName\fR ?\fI...\fR? +.fi +.BE +.SH DESCRIPTION +The \fBclassvariable\fR command is available within methods. It takes a series +of one or more variable names and makes them available in the method's scope; +those variable names must not be qualified and must not refer to array +elements. The originating scope for the variables is the namespace of the +class that the method was defined by. In other words, the referenced variables +are shared between all instances of that class. +.PP +Note: This command is equivalent to the command \fBtypevariable\fR provided by +the snit package in tcllib for approximately the same purpose. If used in a +method defined directly on a class instance (e.g., through the +\fBoo::objdefine\fR \fBmethod\fR definition) this is very much like just +using: +.PP +.CS +namespace upvar [namespace current] $var $var +.CE +.PP +for each variable listed to \fBclassvariable\fR. +.SH EXAMPLE +This class counts how many instances of it have been made. +.PP +.CS +oo::class create Counted { + initialise { + variable count 0 + } + + variable number + constructor {} { + \fBclassvariable\fR count + set number [incr count] + } + + method report {} { + \fBclassvariable\fR count + puts "This is instance $number of $count" + } +} + +set a [Counted new] +set b [Counted new] +$a report + \fI\(-> This is instance 1 of 2\fR +set c [Counted new] +$b report + \fI\(-> This is instance 2 of 3\fR +$c report + \fI\(-> This is instance 3 of 3\fR +.CE +.SH "SEE ALSO" +global(n), namespace(n), oo::class(n), oo::define(n), upvar(n), variable(n) +.SH KEYWORDS +class, class variable, variable +.\" Local Variables: +.\" mode: nroff +.\" fill-column: 78 +.\" End: |
