#include <tcl.h> int Tcl_TraceVar(interp, varName, flags, proc, clientData) int Tcl_TraceVar2(interp, name1, name2, flags, proc, clientData) Tcl_UntraceVar(interp, varName, flags, proc, clientData) Tcl_UntraceVar2(interp, name1, name2, flags, proc, clientData) ClientData Tcl_VarTraceInfo(interp, varName, flags, proc, prevClientData) ClientData Tcl_VarTraceInfo2(interp, name1, name2, flags, proc, prevClientData)
The flags argument to Tcl_TraceVar indicates when the trace procedure is to be invoked and provides information for setting up the trace. It consists of an OR-ed combination of any of the following values:
typedef char *Tcl_VarTraceProc(
ClientData clientData,
Tcl_Interp *interp,
char *name1,
char *name2,
int flags);
The clientData and interp parameters will
have the same values as those passed to Tcl_TraceVar when the
trace was created.
ClientData typically points to an application-specific
data structure that describes what to do when proc
is invoked.
Name1 and name2 give the name of the traced variable
in the normal two-part form (see the description of Tcl_TraceVar2
below for details).
Flags is an OR-ed combination of bits providing several
pieces of information.
One of the bits TCL_TRACE_READS, TCL_TRACE_WRITES, or TCL_TRACE_UNSETS
will be set in flags to indicate which operation is being performed
on the variable.
The bit TCL_GLOBAL_ONLY will be set whenever the variable being
accessed is a global one not accessible from the current level of
procedure call: the trace procedure will need to pass this flag
back to variable-related procedures like Tcl_GetVar if it
attempts to access the variable.
The bit TCL_TRACE_DESTROYED will be set in flags if the trace is
about to be destroyed; this information may be useful to proc
so that it can clean up its own internal data structures (see
the section TCL_TRACE_DESTROYED below for more details).
Lastly, the bit TCL_INTERP_DESTROYED will be set if the entire
interpreter is being destroyed.
When this bit is set, proc must be especially careful in
the things it does (see the section TCL_INTERP_DESTROYED below).
The trace procedure's return value should normally be NULL; see
ERROR RETURNS below for information on other possibilities.
During unset traces the variable has already been completely expunged. It is possible for the trace procedure to read or write the variable, but this will be a new version of the variable. Traces are not disabled during unset traces as they are for read and write traces, but existing traces have been removed from the variable before any trace procedures are invoked. If new traces are set by unset trace procedures, these traces will be invoked on accesses to the variable by the trace procedures.
When write tracing has been specified for a variable, the trace procedure will be invoked whenever the variable's value is modified. This includes set commands, commands that modify variables as side effects (such as catch and scan), and calls to the Tcl_SetVar and Tcl_SetVar2 procedures). Proc will be invoked after the variable's value has been modified, but before the new value of the variable has been returned. It may modify the value of the variable to override the change and to determine the value actually returned by the traced access. If it deletes the variable then the traced access will return an empty string.
When unset tracing has been specified, the trace procedure will be invoked whenever the variable is destroyed. The traces will be called after the variable has been completely unset.
The return value from proc is only used during read and write tracing. During unset traces, the return value is ignored and all relevant trace procedures will always be invoked.
Copyright © 1989-1994 The Regents of the University of California.
Copyright © 1994-1997 Sun Microsystems, Inc.