📄 linkvar.3
字号:
'\"'\" Copyright (c) 1993 The Regents of the University of California.'\" Copyright (c) 1994-1996 Sun Microsystems, Inc.'\"'\" See the file "license.terms" for information on usage and redistribution'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.'\" '\" SCCS: @(#) LinkVar.3 1.15 96/09/05 17:16:57'\" .so man.macros.TH Tcl_LinkVar 3 7.5 Tcl "Tcl Library Procedures".BS.SH NAMETcl_LinkVar, Tcl_UnlinkVar, Tcl_UpdateLinkedVar \- link Tcl variable to C variable.SH SYNOPSIS.nf\fB#include <tcl.h>\fR.spint\fBTcl_LinkVar\fR(\fIinterp, varName, addr, type\fR).sp\fBTcl_UnlinkVar\fR(\fIinterp, varName\fR).sp\fBTcl_UpdateLinkedVar\fR(\fIinterp, varName\fR).SH ARGUMENTS.AS Tcl_Interp writable.AP Tcl_Interp *interp inInterpreter that contains \fIvarName\fR.Also used by \fBTcl_LinkVar\fR to return error messages..AP char *varName inName of global variable. Must be in writable memory: Tcl may maketemporary modifications to it while parsing the variable name..AP char *addr inAddress of C variable that is to be linked to \fIvarName\fR..AP int type inType of C variable. Must be one of TCL_LINK_INT, TCL_LINK_DOUBLE,TCL_LINK_BOOLEAN, or TCL_LINK_STRING, optionally OR'ed withTCL_LINK_READ_ONLY to make Tcl variable read-only..BE.SH DESCRIPTION.PP\fBTcl_LinkVar\fR uses variable traces to keep the Tcl variablenamed by \fIvarName\fR in sync with the C variable at the addressgiven by \fIaddr\fR.Whenever the Tcl variable is read the value of the C variable willbe returned, and whenever the Tcl variable is written the Cvariable will be updated to have the same value.\fBTcl_LinkVar\fR normally returns TCL_OK; if an error occurswhile setting up the link (e.g. because \fIvarName\fR is thename of array) then TCL_ERROR is returned and \fIinterp->result\fRcontains an error message..PPThe \fItype\fR argument specifies the type of the C variable,and must have one of the following values, optionally OR'ed withTCL_LINK_READ_ONLY:.TP\fBTCL_LINK_INT\fRThe C variable is of type \fBint\fR.Any value written into the Tcl variable must have a proper integerform acceptable to \fBTcl_GetInt\fR; attempts to writenon-integer values into \fIvarName\fR will be rejected withTcl errors..TP\fBTCL_LINK_DOUBLE\fRThe C variable is of type \fBdouble\fR.Any value written into the Tcl variable must have a proper realform acceptable to \fBTcl_GetDouble\fR; attempts to writenon-real values into \fIvarName\fR will be rejected withTcl errors..TP\fBTCL_LINK_BOOLEAN\fRThe C variable is of type \fBint\fR.If its value is zero then it will read from Tcl as ``0'';otherwise it will read from Tcl as ``1''.Whenever \fIvarName\fR ismodified, the C variable will be set to a 0 or 1 value.Any value written into the Tcl variable must have a proper booleanform acceptable to \fBTcl_GetBoolean\fR; attempts to writenon-boolean values into \fIvarName\fR will be rejected withTcl errors..TP\fBTCL_LINK_STRING\fRThe C variable is of type \fBchar *\fR..VSIf its value is not null then it must be a pointer to a stringallocated with \fBTcl_Alloc\fR..VEWhenever the Tcl variable is modified the current C string will befreed and new memory will be allocated to hold a copy of the variable'snew value.If the C variable contains a null pointer then the Tcl variablewill read as ``NULL''..PPIf the TCL_LINK_READ_ONLY flag is present in \fItype\fR then thevariable will be read-only from Tcl, so that its value can only bechanged by modifying the C variable.Attempts to write the variable from Tcl will be rejected with errors..PP\fBTcl_UnlinkVar\fR removes the link previously set up for thevariable given by \fIvarName\fR. If there does not exist a linkfor \fIvarName\fR then the procedure has no effect..PP\fBTcl_UpdateLinkedVar\fR may be invoked after the C variable haschanged to force the Tcl variable to be updated immediately.In many cases this procedure is not needed, since any attempt toread the Tcl variable will return the latest value of the C variable.However, if a trace has been set on the Tcl variable (such as aTk widget that wishes to display the value of the variable), thetrace will not trigger when the C variable has changed.\fBTcl_UpdateLinkedVar\fR ensures that any traces on the Tclvariable are invoked..SH KEYWORDSboolean, integer, link, read-only, real, string, traces, variable
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -