| 1 |
'\" |
| 2 |
'\" Copyright (c) 1993 The Regents of the University of California. |
| 3 |
'\" Copyright (c) 1994-1997 Sun Microsystems, Inc. |
| 4 |
'\" Copyright (c) 1993-1997 Bell Labs Innovations for Lucent Technologies |
| 5 |
'\" Copyright (c) 1998-2000 Ajuba Solutions |
| 6 |
'\" Copyright (c) 2007-2012 Donal K. Fellows |
| 7 |
'\" |
| 8 |
'\" See the file "license.terms" for information on usage and redistribution |
| 9 |
'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
| 10 |
'\" |
| 11 |
.TH info n 8.4 Tcl "Tcl Built-In Commands" |
| 12 |
.so man.macros |
| 13 |
.BS |
| 14 |
'\" Note: do not modify the .SH NAME line immediately below! |
| 15 |
.SH NAME |
| 16 |
info \- Return information about the state of the Tcl interpreter |
| 17 |
.SH SYNOPSIS |
| 18 |
\fBinfo \fIoption \fR?\fIarg arg ...\fR? |
| 19 |
.BE |
| 20 |
.SH DESCRIPTION |
| 21 |
.PP |
| 22 |
This command provides information about various internals of the Tcl |
| 23 |
interpreter. |
| 24 |
The legal \fIoption\fRs (which may be abbreviated) are: |
| 25 |
.TP |
| 26 |
\fBinfo args \fIprocname\fR |
| 27 |
. |
| 28 |
Returns a list containing the names of the arguments to procedure |
| 29 |
\fIprocname\fR, in order. \fIProcname\fR must be the name of a |
| 30 |
Tcl command procedure. |
| 31 |
.TP |
| 32 |
\fBinfo body \fIprocname\fR |
| 33 |
. |
| 34 |
Returns the body of procedure \fIprocname\fR. \fIProcname\fR must be |
| 35 |
the name of a Tcl command procedure. |
| 36 |
.TP |
| 37 |
\fBinfo class\fI subcommand class\fR ?\fIarg ...\fR |
| 38 |
.VS 8.6 |
| 39 |
Returns information about the class, \fIclass\fR. The \fIsubcommand\fRs are |
| 40 |
described in \fBCLASS INTROSPECTION\fR below. |
| 41 |
.VE 8.6 |
| 42 |
.TP |
| 43 |
\fBinfo cmdcount\fR |
| 44 |
. |
| 45 |
Returns a count of the total number of commands that have been invoked |
| 46 |
in this interpreter. |
| 47 |
.TP |
| 48 |
\fBinfo commands \fR?\fIpattern\fR? |
| 49 |
. |
| 50 |
If \fIpattern\fR is not specified, |
| 51 |
returns a list of names of all the Tcl commands visible |
| 52 |
(i.e. executable without using a qualified name) to the current namespace, |
| 53 |
including both the built-in commands written in C and |
| 54 |
the command procedures defined using the \fBproc\fR command. |
| 55 |
If \fIpattern\fR is specified, |
| 56 |
only those names matching \fIpattern\fR are returned. |
| 57 |
Matching is determined using the same rules as for \fBstring match\fR. |
| 58 |
\fIpattern\fR can be a qualified name like \fBFoo::print*\fR. |
| 59 |
That is, it may specify a particular namespace |
| 60 |
using a sequence of namespace names separated by double colons (\fB::\fR), |
| 61 |
and may have pattern matching special characters |
| 62 |
at the end to specify a set of commands in that namespace. |
| 63 |
If \fIpattern\fR is a qualified name, |
| 64 |
the resulting list of command names has each one qualified with the name |
| 65 |
of the specified namespace, and only the commands defined in the named |
| 66 |
namespace are returned. |
| 67 |
.\" Technically, most of this hasn't changed; that's mostly just the |
| 68 |
.\" way it always worked. Hardly anyone knew that though. |
| 69 |
.TP |
| 70 |
\fBinfo complete \fIcommand\fR |
| 71 |
. |
| 72 |
Returns 1 if \fIcommand\fR is a complete Tcl command in the sense of |
| 73 |
having no unclosed quotes, braces, brackets or array element names. |
| 74 |
If the command does not appear to be complete then 0 is returned. |
| 75 |
This command is typically used in line-oriented input environments |
| 76 |
to allow users to type in commands that span multiple lines; if the |
| 77 |
command is not complete, the script can delay evaluating it until additional |
| 78 |
lines have been typed to complete the command. |
| 79 |
.TP |
| 80 |
\fBinfo coroutine\fR |
| 81 |
.VS 8.6 |
| 82 |
Returns the name of the currently executing \fBcoroutine\fR, or the empty |
| 83 |
string if either no coroutine is currently executing, or the current coroutine |
| 84 |
has been deleted (but has not yet returned or yielded since deletion). |
| 85 |
.VE 8.6 |
| 86 |
.TP |
| 87 |
\fBinfo default \fIprocname arg varname\fR |
| 88 |
. |
| 89 |
\fIProcname\fR must be the name of a Tcl command procedure and \fIarg\fR |
| 90 |
must be the name of an argument to that procedure. If \fIarg\fR |
| 91 |
does not have a default value then the command returns \fB0\fR. |
| 92 |
Otherwise it returns \fB1\fR and places the default value of \fIarg\fR |
| 93 |
into variable \fIvarname\fR. |
| 94 |
.TP |
| 95 |
\fBinfo errorstack \fR?\fIinterp\fR? |
| 96 |
.VS 8.6 |
| 97 |
Returns, in a form that is programmatically easy to parse, the function names |
| 98 |
and arguments at each level from the call stack of the last error in the given |
| 99 |
\fIinterp\fR, or in the current one if not specified. |
| 100 |
.RS |
| 101 |
.PP |
| 102 |
This form is an even-sized list alternating tokens and parameters. Tokens are |
| 103 |
currently either \fBCALL\fR, \fBUP\fR, or \fBINNER\fR, but other values may be |
| 104 |
introduced in the future. \fBCALL\fR indicates a procedure call, and its |
| 105 |
parameter is the corresponding \fBinfo level\fR \fB0\fR. \fBUP\fR indicates a |
| 106 |
shift in variable frames generated by \fBuplevel\fR or similar, and applies to |
| 107 |
the previous \fBCALL\fR item. Its parameter is the level offset. \fBINNER\fR |
| 108 |
identifies the |
| 109 |
.QW "inner context" , |
| 110 |
which is the innermost atomic command or bytecode instruction that raised the |
| 111 |
error, along with its arguments when available. While \fBCALL\fR and \fBUP\fR |
| 112 |
allow to follow complex call paths, \fBINNER\fR homes in on the offending |
| 113 |
operation in the innermost procedure call, even going to sub-expression |
| 114 |
granularity. |
| 115 |
.PP |
| 116 |
This information is also present in the \fB\-errorstack\fR entry of the |
| 117 |
options dictionary returned by 3-argument \fBcatch\fR; \fBinfo errorstack\fR |
| 118 |
is a convenient way of retrieving it for uncaught errors at top-level in an |
| 119 |
interactive \fBtclsh\fR. |
| 120 |
.RE |
| 121 |
.VE 8.6 |
| 122 |
.TP |
| 123 |
\fBinfo exists \fIvarName\fR |
| 124 |
. |
| 125 |
Returns \fB1\fR if the variable named \fIvarName\fR exists in the |
| 126 |
current context (either as a global or local variable) and has been |
| 127 |
defined by being given a value, returns \fB0\fR otherwise. |
| 128 |
.TP |
| 129 |
\fBinfo frame\fR ?\fInumber\fR? |
| 130 |
. |
| 131 |
This command provides access to all frames on the stack, even those |
| 132 |
hidden from \fBinfo level\fR. If \fInumber\fR is not specified, this |
| 133 |
command returns a number giving the frame level of the command. This |
| 134 |
is 1 if the command is invoked at top-level. If \fInumber\fR is |
| 135 |
specified, then the result is a dictionary containing the location |
| 136 |
information for the command at the \fInumber\fRed level on the stack. |
| 137 |
.RS |
| 138 |
.PP |
| 139 |
If \fInumber\fR is positive (> 0) then it selects a particular stack |
| 140 |
level (1 refers to the outer-most active command, 2 to the command it |
| 141 |
called, and so on, up to the current frame level which refers to |
| 142 |
\fBinfo frame\fR itself); otherwise it gives a level relative to the |
| 143 |
current command (0 refers to the current command, i.e., \fBinfo |
| 144 |
frame\fR itself, -1 to its caller, and so on). |
| 145 |
.PP |
| 146 |
This is similar to how \fBinfo level\fR works, except that this |
| 147 |
subcommand reports all frames, like \fBsource\fRd scripts, |
| 148 |
\fBeval\fRs, \fBuplevel\fRs, etc. |
| 149 |
.PP |
| 150 |
Note that for nested commands, like |
| 151 |
.QW "foo [bar [x]]" , |
| 152 |
only |
| 153 |
.QW x |
| 154 |
will be seen by an \fBinfo frame\fR invoked within |
| 155 |
.QW x . |
| 156 |
This is the same as for \fBinfo level\fR and error stack traces. |
| 157 |
.PP |
| 158 |
The result dictionary may contain the keys listed below, with the |
| 159 |
specified meanings for their values: |
| 160 |
.TP |
| 161 |
\fBtype\fR |
| 162 |
. |
| 163 |
This entry is always present and describes the nature of the location |
| 164 |
for the command. The recognized values are \fBsource\fR, \fBproc\fR, |
| 165 |
\fBeval\fR, and \fBprecompiled\fR. |
| 166 |
.RS |
| 167 |
.TP |
| 168 |
\fBsource\fR\0\0\0\0\0\0\0\0 |
| 169 |
. |
| 170 |
means that the command is found in a script loaded by the \fBsource\fR |
| 171 |
command. |
| 172 |
.TP |
| 173 |
\fBproc\fR\0\0\0\0\0\0\0\0 |
| 174 |
. |
| 175 |
means that the command is found in dynamically created procedure body. |
| 176 |
.TP |
| 177 |
\fBeval\fR\0\0\0\0\0\0\0\0 |
| 178 |
. |
| 179 |
means that the command is executed by \fBeval\fR or \fBuplevel\fR. |
| 180 |
.TP |
| 181 |
\fBprecompiled\fR\0\0\0\0\0\0\0\0 |
| 182 |
. |
| 183 |
means that the command is found in a precompiled script (loadable by |
| 184 |
the package \fBtbcload\fR), and no further information will be |
| 185 |
available. |
| 186 |
.RE |
| 187 |
.TP |
| 188 |
\fBline\fR |
| 189 |
. |
| 190 |
This entry provides the number of the line the command is at inside of |
| 191 |
the script it is a part of. This information is not present for type |
| 192 |
\fBprecompiled\fR. For type \fBsource\fR this information is counted |
| 193 |
relative to the beginning of the file, whereas for the last two types |
| 194 |
the line is counted relative to the start of the script. |
| 195 |
.TP |
| 196 |
\fBfile\fR |
| 197 |
. |
| 198 |
This entry is present only for type \fBsource\fR. It provides the |
| 199 |
normalized path of the file the command is in. |
| 200 |
.TP |
| 201 |
\fBcmd\fR |
| 202 |
. |
| 203 |
This entry provides the string representation of the command. This is |
| 204 |
usually the unsubstituted form, however for commands which are a |
| 205 |
canonically-constructed list (e.g., as produced by the \fBlist\fR command) |
| 206 |
executed by \fBeval\fR it is the substituted form as they have no other |
| 207 |
string representation. Care is taken that the canonicality property of |
| 208 |
the latter is not spoiled. |
| 209 |
.TP |
| 210 |
\fBproc\fR |
| 211 |
. |
| 212 |
This entry is present only if the command is found in the body of a |
| 213 |
regular Tcl procedure. It then provides the name of that procedure. |
| 214 |
.TP |
| 215 |
\fBlambda\fR |
| 216 |
. |
| 217 |
This entry is present only if the command is found in the body of an |
| 218 |
anonymous Tcl procedure, i.e. a lambda. It then provides the entire |
| 219 |
definition of the lambda in question. |
| 220 |
.TP |
| 221 |
\fBlevel\fR |
| 222 |
. |
| 223 |
This entry is present only if the queried frame has a corresponding |
| 224 |
frame returned by \fBinfo level\fR. It provides the index of this |
| 225 |
frame, relative to the current level (0 and negative numbers). |
| 226 |
.PP |
| 227 |
A thing of note is that for procedures statically defined in files the |
| 228 |
locations of commands in their bodies will be reported with type |
| 229 |
\fBsource\fR and absolute line numbers, and not as type |
| 230 |
\fBproc\fR. The same is true for procedures nested in statically |
| 231 |
defined procedures, and literal eval scripts in files or statically |
| 232 |
defined procedures. |
| 233 |
.PP |
| 234 |
In contrast, procedure definitions and \fBeval\fR within a dynamically |
| 235 |
\fBeval\fRuated environment count line numbers relative to the start of |
| 236 |
their script, even if they would be able to count relative to the |
| 237 |
start of the outer dynamic script. That type of number usually makes |
| 238 |
more sense. |
| 239 |
.PP |
| 240 |
A different way of describing this behaviour is that file based |
| 241 |
locations are tracked as deeply as possible, and where this is not |
| 242 |
possible the lines are counted based on the smallest possible |
| 243 |
\fBeval\fR or procedure body, as that scope is usually easier to find |
| 244 |
than any dynamic outer scope. |
| 245 |
.PP |
| 246 |
The syntactic form \fB{*}\fR is handled like \fBeval\fR. I.e. if it |
| 247 |
is given a literal list argument the system tracks the line number |
| 248 |
within the list words as well, and otherwise all line numbers are |
| 249 |
counted relative to the start of each word (smallest scope) |
| 250 |
.RE |
| 251 |
.TP |
| 252 |
\fBinfo functions \fR?\fIpattern\fR? |
| 253 |
. |
| 254 |
If \fIpattern\fR is not specified, returns a list of all the math |
| 255 |
functions currently defined. |
| 256 |
If \fIpattern\fR is specified, only those functions whose name matches |
| 257 |
\fIpattern\fR are returned. Matching is determined using the same |
| 258 |
rules as for \fBstring match\fR. |
| 259 |
.TP |
| 260 |
\fBinfo globals \fR?\fIpattern\fR? |
| 261 |
. |
| 262 |
If \fIpattern\fR is not specified, returns a list of all the names |
| 263 |
of currently-defined global variables. |
| 264 |
Global variables are variables in the global namespace. |
| 265 |
If \fIpattern\fR is specified, only those names matching \fIpattern\fR |
| 266 |
are returned. Matching is determined using the same rules as for |
| 267 |
\fBstring match\fR. |
| 268 |
.TP |
| 269 |
\fBinfo hostname\fR |
| 270 |
. |
| 271 |
Returns the name of the computer on which this invocation is being |
| 272 |
executed. |
| 273 |
Note that this name is not guaranteed to be the fully qualified domain |
| 274 |
name of the host. Where machines have several different names (as is |
| 275 |
common on systems with both TCP/IP (DNS) and NetBIOS-based networking |
| 276 |
installed,) it is the name that is suitable for TCP/IP networking that |
| 277 |
is returned. |
| 278 |
.TP |
| 279 |
\fBinfo level\fR ?\fInumber\fR? |
| 280 |
. |
| 281 |
If \fInumber\fR is not specified, this command returns a number |
| 282 |
giving the stack level of the invoking procedure, or 0 if the |
| 283 |
command is invoked at top-level. If \fInumber\fR is specified, |
| 284 |
then the result is a list consisting of the name and arguments for the |
| 285 |
procedure call at level \fInumber\fR on the stack. If \fInumber\fR |
| 286 |
is positive then it selects a particular stack level (1 refers |
| 287 |
to the top-most active procedure, 2 to the procedure it called, and |
| 288 |
so on); otherwise it gives a level relative to the current level |
| 289 |
(0 refers to the current procedure, -1 to its caller, and so on). |
| 290 |
See the \fBuplevel\fR command for more information on what stack |
| 291 |
levels mean. |
| 292 |
.TP |
| 293 |
\fBinfo library\fR |
| 294 |
. |
| 295 |
Returns the name of the library directory in which standard Tcl |
| 296 |
scripts are stored. |
| 297 |
This is actually the value of the \fBtcl_library\fR |
| 298 |
variable and may be changed by setting \fBtcl_library\fR. |
| 299 |
.TP |
| 300 |
\fBinfo loaded \fR?\fIinterp\fR? |
| 301 |
. |
| 302 |
Returns a list describing all of the packages that have been loaded into |
| 303 |
\fIinterp\fR with the \fBload\fR command. |
| 304 |
Each list element is a sub-list with two elements consisting of the |
| 305 |
name of the file from which the package was loaded and the name of |
| 306 |
the package. |
| 307 |
For statically-loaded packages the file name will be an empty string. |
| 308 |
If \fIinterp\fR is omitted then information is returned for all packages |
| 309 |
loaded in any interpreter in the process. |
| 310 |
To get a list of just the packages in the current interpreter, specify |
| 311 |
an empty string for the \fIinterp\fR argument. |
| 312 |
.TP |
| 313 |
\fBinfo locals \fR?\fIpattern\fR? |
| 314 |
. |
| 315 |
If \fIpattern\fR is not specified, returns a list of all the names |
| 316 |
of currently-defined local variables, including arguments to the |
| 317 |
current procedure, if any. |
| 318 |
Variables defined with the \fBglobal\fR, \fBupvar\fR and |
| 319 |
\fBvariable\fR commands will not be returned. |
| 320 |
If \fIpattern\fR is specified, only those names matching \fIpattern\fR |
| 321 |
are returned. Matching is determined using the same rules as for |
| 322 |
\fBstring match\fR. |
| 323 |
.TP |
| 324 |
\fBinfo nameofexecutable\fR |
| 325 |
. |
| 326 |
Returns the full path name of the binary file from which the application |
| 327 |
was invoked. If Tcl was unable to identify the file, then an empty |
| 328 |
string is returned. |
| 329 |
.TP |
| 330 |
\fBinfo object\fI subcommand object\fR ?\fIarg ...\fR |
| 331 |
.VS 8.6 |
| 332 |
Returns information about the object, \fIobject\fR. The \fIsubcommand\fRs are |
| 333 |
described in \fBOBJECT INTROSPECTION\fR below. |
| 334 |
.VE 8.6 |
| 335 |
.TP |
| 336 |
\fBinfo patchlevel\fR |
| 337 |
. |
| 338 |
Returns the value of the global variable \fBtcl_patchLevel\fR, which holds |
| 339 |
the exact version of the Tcl library by default. |
| 340 |
.TP |
| 341 |
\fBinfo procs \fR?\fIpattern\fR? |
| 342 |
. |
| 343 |
If \fIpattern\fR is not specified, returns a list of all the |
| 344 |
names of Tcl command procedures in the current namespace. |
| 345 |
If \fIpattern\fR is specified, |
| 346 |
only those procedure names in the current namespace |
| 347 |
matching \fIpattern\fR are returned. |
| 348 |
Matching is determined using the same rules as for |
| 349 |
\fBstring match\fR. |
| 350 |
If \fIpattern\fR contains any namespace separators, they are used to |
| 351 |
select a namespace relative to the current namespace (or relative to |
| 352 |
the global namespace if \fIpattern\fR starts with \fB::\fR) to match |
| 353 |
within; the matching pattern is taken to be the part after the last |
| 354 |
namespace separator. |
| 355 |
.TP |
| 356 |
\fBinfo script\fR ?\fIfilename\fR? |
| 357 |
. |
| 358 |
If a Tcl script file is currently being evaluated (i.e. there is a |
| 359 |
call to \fBTcl_EvalFile\fR active or there is an active invocation |
| 360 |
of the \fBsource\fR command), then this command returns the name |
| 361 |
of the innermost file being processed. If \fIfilename\fR is specified, |
| 362 |
then the return value of this command will be modified for the |
| 363 |
duration of the active invocation to return that name. This is |
| 364 |
useful in virtual file system applications. |
| 365 |
Otherwise the command returns an empty string. |
| 366 |
.TP |
| 367 |
\fBinfo sharedlibextension\fR |
| 368 |
. |
| 369 |
Returns the extension used on this platform for the names of files |
| 370 |
containing shared libraries (for example, \fB.so\fR under Solaris). |
| 371 |
If shared libraries are not supported on this platform then an empty |
| 372 |
string is returned. |
| 373 |
.TP |
| 374 |
\fBinfo tclversion\fR |
| 375 |
. |
| 376 |
Returns the value of the global variable \fBtcl_version\fR, which holds the |
| 377 |
major and minor version of the Tcl library by default. |
| 378 |
.TP |
| 379 |
\fBinfo vars\fR ?\fIpattern\fR? |
| 380 |
. |
| 381 |
If \fIpattern\fR is not specified, |
| 382 |
returns a list of all the names of currently-visible variables. |
| 383 |
This includes locals and currently-visible globals. |
| 384 |
If \fIpattern\fR is specified, only those names matching \fIpattern\fR |
| 385 |
are returned. Matching is determined using the same rules as for |
| 386 |
\fBstring match\fR. |
| 387 |
\fIpattern\fR can be a qualified name like \fBFoo::option*\fR. |
| 388 |
That is, it may specify a particular namespace |
| 389 |
using a sequence of namespace names separated by double colons (\fB::\fR), |
| 390 |
and may have pattern matching special characters |
| 391 |
at the end to specify a set of variables in that namespace. |
| 392 |
If \fIpattern\fR is a qualified name, |
| 393 |
the resulting list of variable names |
| 394 |
has each matching namespace variable qualified with the name |
| 395 |
of its namespace. |
| 396 |
Note that a currently-visible variable may not yet |
| 397 |
.QW exist |
| 398 |
if it has not |
| 399 |
been set (e.g. a variable declared but not set by \fBvariable\fR). |
| 400 |
.SS "CLASS INTROSPECTION" |
| 401 |
.VS 8.6 |
| 402 |
.PP |
| 403 |
The following \fIsubcommand\fR values are supported by \fBinfo class\fR: |
| 404 |
.VE 8.6 |
| 405 |
.TP |
| 406 |
\fBinfo class call\fI class method\fR |
| 407 |
.VS |
| 408 |
Returns a description of the method implementations that are used to provide a |
| 409 |
stereotypical instance of \fIclass\fR's implementation of \fImethod\fR |
| 410 |
(stereotypical instances being objects instantiated by a class without having |
| 411 |
any object-specific definitions added). This consists of a list of lists of |
| 412 |
four elements, where each sublist consists of a word that describes the |
| 413 |
general type of method implementation (being one of \fBmethod\fR for an |
| 414 |
ordinary method, \fBfilter\fR for an applied filter, and \fBunknown\fR for a |
| 415 |
method that is invoked as part of unknown method handling), a word giving the |
| 416 |
name of the particular method invoked (which is always the same as |
| 417 |
\fImethod\fR for the \fBmethod\fR type, and |
| 418 |
.QW \fBunknown\fR |
| 419 |
for the \fBunknown\fR type), a word giving the fully qualified name of the |
| 420 |
class that defined the method, and a word describing the type of method |
| 421 |
implementation (see \fBinfo class methodtype\fR). |
| 422 |
.RS |
| 423 |
.PP |
| 424 |
Note that there is no inspection of whether the method implementations |
| 425 |
actually use \fBnext\fR to transfer control along the call chain. |
| 426 |
.RE |
| 427 |
.VE 8.6 |
| 428 |
.TP |
| 429 |
\fBinfo class constructor\fI class\fR |
| 430 |
.VS 8.6 |
| 431 |
This subcommand returns a description of the definition of the constructor of |
| 432 |
class \fIclass\fR. The definition is described as a two element list; the first |
| 433 |
element is the list of arguments to the constructor in a form suitable for |
| 434 |
passing to another call to \fBproc\fR or a method definition, and the second |
| 435 |
element is the body of the constructor. If no constructor is present, this |
| 436 |
returns the empty list. |
| 437 |
.VE 8.6 |
| 438 |
.TP |
| 439 |
\fBinfo class definition\fI class method\fR |
| 440 |
.VS 8.6 |
| 441 |
This subcommand returns a description of the definition of the method named |
| 442 |
\fImethod\fR of class \fIclass\fR. The definition is described as a two element |
| 443 |
list; the first element is the list of arguments to the method in a form |
| 444 |
suitable for passing to another call to \fBproc\fR or a method definition, and |
| 445 |
the second element is the body of the method. |
| 446 |
.VE 8.6 |
| 447 |
.TP |
| 448 |
\fBinfo class destructor\fI class\fR |
| 449 |
.VS 8.6 |
| 450 |
This subcommand returns the body of the destructor of class \fIclass\fR. If no |
| 451 |
destructor is present, this returns the empty string. |
| 452 |
.VE 8.6 |
| 453 |
.TP |
| 454 |
\fBinfo class filters\fI class\fR |
| 455 |
.VS 8.6 |
| 456 |
This subcommand returns the list of filter methods set on the class. |
| 457 |
.VE 8.6 |
| 458 |
.TP |
| 459 |
\fBinfo class forward\fI class method\fR |
| 460 |
.VS 8.6 |
| 461 |
This subcommand returns the argument list for the method forwarding called |
| 462 |
\fImethod\fR that is set on the class called \fIclass\fR. |
| 463 |
.VE 8.6 |
| 464 |
.TP |
| 465 |
\fBinfo class instances\fI class\fR ?\fIpattern\fR? |
| 466 |
.VS 8.6 |
| 467 |
This subcommand returns a list of instances of class \fIclass\fR. If the |
| 468 |
optional \fIpattern\fR argument is present, it constrains the list of returned |
| 469 |
instances to those that match it according to the rules of \fBstring match\fR. |
| 470 |
.VE 8.6 |
| 471 |
.TP |
| 472 |
\fBinfo class methods\fI class\fR ?\fIoptions...\fR? |
| 473 |
.VS 8.6 |
| 474 |
This subcommand returns a list of all public (i.e. exported) methods of the |
| 475 |
class called \fIclass\fR. Any of the following \fIoption\fRs may be |
| 476 |
specified, controlling exactly which method names are returned: |
| 477 |
.RS |
| 478 |
.VE 8.6 |
| 479 |
.TP |
| 480 |
\fB\-all\fR |
| 481 |
.VS 8.6 |
| 482 |
If the \fB\-all\fR flag is given, the list of methods will include those |
| 483 |
methods defined not just by the class, but also by the class's superclasses |
| 484 |
and mixins. |
| 485 |
.VE 8.6 |
| 486 |
.TP |
| 487 |
\fB\-private\fR |
| 488 |
.VS 8.6 |
| 489 |
If the \fB\-private\fR flag is given, the list of methods will also include |
| 490 |
the private (i.e. non-exported) methods of the class (and superclasses and |
| 491 |
mixins, if \fB\-all\fR is also given). |
| 492 |
.RE |
| 493 |
.VE 8.6 |
| 494 |
.TP |
| 495 |
\fBinfo class methodtype\fI class method\fR |
| 496 |
.VS 8.6 |
| 497 |
This subcommand returns a description of the type of implementation used for |
| 498 |
the method named \fImethod\fR of class \fIclass\fR. When the result is |
| 499 |
\fBmethod\fR, further information can be discovered with \fBinfo class |
| 500 |
definition\fR, and when the result is \fBforward\fR, further information can |
| 501 |
be discovered with \fBinfo class forward\fR. |
| 502 |
.VE 8.6 |
| 503 |
.TP |
| 504 |
\fBinfo class mixins\fI class\fR |
| 505 |
.VS 8.6 |
| 506 |
This subcommand returns a list of all classes that have been mixed into the |
| 507 |
class named \fIclass\fR. |
| 508 |
.VE 8.6 |
| 509 |
.TP |
| 510 |
\fBinfo class subclasses\fI class\fR ?\fIpattern\fR? |
| 511 |
.VS 8.6 |
| 512 |
This subcommand returns a list of direct subclasses of class \fIclass\fR. If |
| 513 |
the optional \fIpattern\fR argument is present, it constrains the list of |
| 514 |
returned classes to those that match it according to the rules of |
| 515 |
\fBstring match\fR. |
| 516 |
.VE 8.6 |
| 517 |
.TP |
| 518 |
\fBinfo class superclasses\fI class\fR |
| 519 |
.VS 8.6 |
| 520 |
This subcommand returns a list of direct superclasses of class \fIclass\fR in |
| 521 |
inheritance precedence order. |
| 522 |
.VE 8.6 |
| 523 |
.TP |
| 524 |
\fBinfo class variables\fI class\fR |
| 525 |
.VS 8.6 |
| 526 |
This subcommand returns a list of all variables that have been declared for |
| 527 |
the class named \fIclass\fR (i.e. that are automatically present in the |
| 528 |
class's methods, constructor and destructor). |
| 529 |
.SS "OBJECT INTROSPECTION" |
| 530 |
.PP |
| 531 |
The following \fIsubcommand\fR values are supported by \fBinfo object\fR: |
| 532 |
.VE 8.6 |
| 533 |
.TP |
| 534 |
\fBinfo object call\fI object method\fR |
| 535 |
.VS 8.6 |
| 536 |
Returns a description of the method implementations that are used to provide |
| 537 |
\fIobject\fR's implementation of \fImethod\fR. This consists of a list of |
| 538 |
lists of four elements, where each sublist consists of a word that describes |
| 539 |
the general type of method implementation (being one of \fBmethod\fR for an |
| 540 |
ordinary method, \fBfilter\fR for an applied filter, and \fBunknown\fR for a |
| 541 |
method that is invoked as part of unknown method handling), a word giving the |
| 542 |
name of the particular method invoked (which is always the same as |
| 543 |
\fImethod\fR for the \fBmethod\fR type, and |
| 544 |
.QW \fBunknown\fR |
| 545 |
for the \fBunknown\fR type), a word giving what defined the method (the fully |
| 546 |
qualified name of the class, or the literal string \fBobject\fR if the method |
| 547 |
implementation is on an instance), and a word describing the type of method |
| 548 |
implementation (see \fBinfo object methodtype\fR). |
| 549 |
.RS |
| 550 |
.PP |
| 551 |
Note that there is no inspection of whether the method implementations |
| 552 |
actually use \fBnext\fR to transfer control along the call chain. |
| 553 |
.RE |
| 554 |
.VE 8.6 |
| 555 |
.TP |
| 556 |
\fBinfo object class\fI object\fR ?\fIclassName\fR? |
| 557 |
.VS 8.6 |
| 558 |
If \fIclassName\fR is unspecified, this subcommand returns class of the |
| 559 |
\fIobject\fR object. If \fIclassName\fR is present, this subcommand returns a |
| 560 |
boolean value indicating whether the \fIobject\fR is of that class. |
| 561 |
.VE 8.6 |
| 562 |
.TP |
| 563 |
\fBinfo object definition\fI object method\fR |
| 564 |
.VS 8.6 |
| 565 |
This subcommand returns a description of the definition of the method named |
| 566 |
\fImethod\fR of object \fIobject\fR. The definition is described as a two |
| 567 |
element list; the first element is the list of arguments to the method in a |
| 568 |
form suitable for passing to another call to \fBproc\fR or a method definition, |
| 569 |
and the second element is the body of the method. |
| 570 |
.VE 8.6 |
| 571 |
.TP |
| 572 |
\fBinfo object filters\fI object\fR |
| 573 |
.VS 8.6 |
| 574 |
This subcommand returns the list of filter methods set on the object. |
| 575 |
.VE 8.6 |
| 576 |
.TP |
| 577 |
\fBinfo object forward\fI object method\fR |
| 578 |
.VS 8.6 |
| 579 |
This subcommand returns the argument list for the method forwarding called |
| 580 |
\fImethod\fR that is set on the object called \fIobject\fR. |
| 581 |
.VE 8.6 |
| 582 |
.TP |
| 583 |
\fBinfo object isa\fI category object\fR ?\fIarg\fR? |
| 584 |
.VS 8.6 |
| 585 |
This subcommand tests whether an object belongs to a particular category, |
| 586 |
returning a boolean value that indicates whether the \fIobject\fR argument |
| 587 |
meets the criteria for the category. The supported categories are: |
| 588 |
.VE 8.6 |
| 589 |
.RS |
| 590 |
.TP |
| 591 |
\fBinfo object isa class\fI object\fR |
| 592 |
.VS 8.6 |
| 593 |
This returns whether \fIobject\fR is a class (i.e. an instance of |
| 594 |
\fBoo::class\fR or one of its subclasses). |
| 595 |
.VE 8.6 |
| 596 |
.TP |
| 597 |
\fBinfo object isa metaclass\fI object\fR |
| 598 |
.VS 8.6 |
| 599 |
This returns whether \fIobject\fR is a class that can manufacture classes |
| 600 |
(i.e. is \fBoo::class\fR or a subclass of it). |
| 601 |
.VE 8.6 |
| 602 |
.TP |
| 603 |
\fBinfo object isa mixin\fI object class\fR |
| 604 |
.VS 8.6 |
| 605 |
This returns whether \fIclass\fR is directly mixed into \fIobject\fR. |
| 606 |
.VE 8.6 |
| 607 |
.TP |
| 608 |
\fBinfo object isa object\fI object\fR |
| 609 |
.VS 8.6 |
| 610 |
This returns whether \fIobject\fR really is an object. |
| 611 |
.VE 8.6 |
| 612 |
.TP |
| 613 |
\fBinfo object isa typeof\fI object class\fR |
| 614 |
.VS 8.6 |
| 615 |
This returns whether \fIclass\fR is the type of \fIobject\fR (i.e. whether |
| 616 |
\fIobject\fR is an instance of \fIclass\fR or one of its subclasses, whether |
| 617 |
direct or indirect). |
| 618 |
.RE |
| 619 |
.VE 8.6 |
| 620 |
.TP |
| 621 |
\fBinfo object methods\fI object\fR ?\fIoption...\fR? |
| 622 |
.VS 8.6 |
| 623 |
This subcommand returns a list of all public (i.e. exported) methods of the |
| 624 |
object called \fIobject\fR. Any of the following \fIoption\fRs may be |
| 625 |
specified, controlling exactly which method names are returned: |
| 626 |
.RS |
| 627 |
.VE 8.6 |
| 628 |
.TP |
| 629 |
\fB\-all\fR |
| 630 |
.VS 8.6 |
| 631 |
If the \fB\-all\fR flag is given, the list of methods will include those |
| 632 |
methods defined not just by the object, but also by the object's class and |
| 633 |
mixins, plus the superclasses of those classes. |
| 634 |
.VE 8.6 |
| 635 |
.TP |
| 636 |
\fB\-private\fR |
| 637 |
.VS 8.6 |
| 638 |
If the \fB\-private\fR flag is given, the list of methods will also include |
| 639 |
the private (i.e. non-exported) methods of the object (and classes, if |
| 640 |
\fB\-all\fR is also given). |
| 641 |
.RE |
| 642 |
.VE 8.6 |
| 643 |
.TP |
| 644 |
\fBinfo object methodtype\fI object method\fR |
| 645 |
.VS 8.6 |
| 646 |
This subcommand returns a description of the type of implementation used for |
| 647 |
the method named \fImethod\fR of object \fIobject\fR. When the result is |
| 648 |
\fBmethod\fR, further information can be discovered with \fBinfo object |
| 649 |
definition\fR, and when the result is \fBforward\fR, further information can |
| 650 |
be discovered with \fBinfo object forward\fR. |
| 651 |
.VE 8.6 |
| 652 |
.TP |
| 653 |
\fBinfo object mixins\fI object\fR |
| 654 |
.VS 8.6 |
| 655 |
This subcommand returns a list of all classes that have been mixed into the |
| 656 |
object named \fIobject\fR. |
| 657 |
.VE 8.6 |
| 658 |
.TP |
| 659 |
\fBinfo object namespace\fI object\fR |
| 660 |
.VS 8.6 |
| 661 |
This subcommand returns the name of the internal namespace of the object named |
| 662 |
\fIobject\fR. |
| 663 |
.VE 8.6 |
| 664 |
.TP |
| 665 |
\fBinfo object variables\fI object\fR |
| 666 |
.VS 8.6 |
| 667 |
This subcommand returns a list of all variables that have been declared for |
| 668 |
the object named \fIobject\fR (i.e. that are automatically present in the |
| 669 |
object's methods). |
| 670 |
.VE 8.6 |
| 671 |
.TP |
| 672 |
\fBinfo object vars\fI object\fR ?\fIpattern\fR? |
| 673 |
.VS 8.6 |
| 674 |
This subcommand returns a list of all variables in the private namespace of |
| 675 |
the object named \fIobject\fR. If the optional \fIpattern\fR argument is |
| 676 |
given, it is a filter (in the syntax of a \fBstring match\fR glob pattern) |
| 677 |
that constrains the list of variables returned. Note that this is different |
| 678 |
from the list returned by \fBinfo object variables\fR; that can include |
| 679 |
variables that are currently unset, whereas this can include variables that |
| 680 |
are not automatically included by any of \fIobject\fR's methods (or those of |
| 681 |
its class, superclasses or mixins). |
| 682 |
.VE 8.6 |
| 683 |
.SH EXAMPLES |
| 684 |
.PP |
| 685 |
This command prints out a procedure suitable for saving in a Tcl |
| 686 |
script: |
| 687 |
.PP |
| 688 |
.CS |
| 689 |
proc printProc {procName} { |
| 690 |
set result [list proc $procName] |
| 691 |
set formals {} |
| 692 |
foreach var [\fBinfo args\fR $procName] { |
| 693 |
if {[\fBinfo default\fR $procName $var def]} { |
| 694 |
lappend formals [list $var $def] |
| 695 |
} else { |
| 696 |
# Still need the list-quoting because variable |
| 697 |
# names may properly contain spaces. |
| 698 |
lappend formals [list $var] |
| 699 |
} |
| 700 |
} |
| 701 |
puts [lappend result $formals [\fBinfo body\fR $procName]] |
| 702 |
} |
| 703 |
.CE |
| 704 |
.SS "EXAMPLES WITH OBJECTS" |
| 705 |
.VS 8.6 |
| 706 |
.PP |
| 707 |
Every object necessarily knows what its class is; this information is |
| 708 |
trivially extractable through introspection: |
| 709 |
.PP |
| 710 |
.CS |
| 711 |
oo::class create c |
| 712 |
c create o |
| 713 |
puts [\fBinfo object class\fR o] |
| 714 |
\fI\(-> prints "::c"\fR |
| 715 |
puts [\fBinfo object class\fR c] |
| 716 |
\fI\(-> prints "::oo::class"\fR |
| 717 |
.CE |
| 718 |
.PP |
| 719 |
The introspection capabilities can be used to discover what class implements a |
| 720 |
method and get how it is defined. This procedure illustrates how: |
| 721 |
.PP |
| 722 |
.CS |
| 723 |
proc getDef {obj method} { |
| 724 |
foreach inf [\fBinfo object call\fR $obj $method] { |
| 725 |
lassign $inf calltype name locus methodtype |
| 726 |
# Assume no forwards or filters, and hence no $calltype |
| 727 |
# or $methodtype checks... |
| 728 |
if {$locus eq "object"} { |
| 729 |
return [\fBinfo object definition\fR $obj $name] |
| 730 |
} else { |
| 731 |
return [\fBinfo class definition\fR $locus $name] |
| 732 |
} |
| 733 |
} |
| 734 |
error "no definition for $method" |
| 735 |
} |
| 736 |
.CE |
| 737 |
.PP |
| 738 |
This is an alternate way of looking up the definition; it is implemented by |
| 739 |
manually scanning the list of methods up the inheritance tree. This code |
| 740 |
assumes that only single inheritance is in use, and that there is no complex |
| 741 |
use of mixed-in classes (in such cases, using \fBinfo object call\fR as above |
| 742 |
is the simplest way of doing this by far): |
| 743 |
.PP |
| 744 |
.CS |
| 745 |
proc getDef {obj method} { |
| 746 |
if {$method in [\fBinfo object methods\fR $obj]} { |
| 747 |
# Assume no forwards |
| 748 |
return [\fBinfo object definition\fR $obj $method] |
| 749 |
} |
| 750 |
set cls [\fBinfo object class\fR $obj] |
| 751 |
while {$method ni [\fBinfo class methods\fR $cls]} { |
| 752 |
# Assume the simple case |
| 753 |
set cls [lindex [\fBinfo class superclass\fR $cls] 0] |
| 754 |
if {$cls eq ""} { |
| 755 |
error "no definition for $method" |
| 756 |
} |
| 757 |
} |
| 758 |
# Assume no forwards |
| 759 |
return [\fBinfo class definition\fR $cls $method] |
| 760 |
} |
| 761 |
.CE |
| 762 |
.VE 8.6 |
| 763 |
.SH "SEE ALSO" |
| 764 |
.VS 8.6 |
| 765 |
global(n), oo::class(n), oo::define(n), oo::object(n), proc(n), self(n), |
| 766 |
.VE 8.6 |
| 767 |
tcl_library(n), tcl_patchLevel(n), tcl_version(n) |
| 768 |
.SH KEYWORDS |
| 769 |
command, information, interpreter, introspection, level, namespace, |
| 770 |
.VS 8.6 |
| 771 |
object, |
| 772 |
.VE 8.6 |
| 773 |
procedure, variable |
| 774 |
'\" Local Variables: |
| 775 |
'\" mode: nroff |
| 776 |
'\" fill-column: 78 |
| 777 |
'\" End: |