1Tcl_LinkVar(3)              Tcl Library Procedures              Tcl_LinkVar(3)
2
3
4
5______________________________________________________________________________
6

NAME

8       Tcl_LinkVar,  Tcl_UnlinkVar, Tcl_UpdateLinkedVar - link Tcl variable to
9       C variable
10

SYNOPSIS

12       #include <tcl.h>
13
14       int
15       Tcl_LinkVar(interp, varName, addr, type)
16
17       Tcl_UnlinkVar(interp, varName)
18
19       Tcl_UpdateLinkedVar(interp, varName)
20

ARGUMENTS

22       Tcl_Interp   *interp    (in)      Interpreter  that  contains  varName.
23                                         Also  used  by  Tcl_LinkVar to return
24                                         error messages.
25
26       CONST char   *varName   (in)      Name of global variable.
27
28       char         *addr      (in)      Address of C variable that is  to  be
29                                         linked to varName.
30
31       int          type       (in)      Type  of  C variable.  Must be one of
32                                         TCL_LINK_INT,        TCL_LINK_DOUBLE, │
33                                         TCL_LINK_WIDE_INT,  TCL_LINK_BOOLEAN,
34                                         or TCL_LINK_STRING, optionally  OR'ed
35                                         with  TCL_LINK_READ_ONLY  to make Tcl
36                                         variable read-only.
37_________________________________________________________________
38
39

DESCRIPTION

41       Tcl_LinkVar uses variable traces to keep the Tcl variable named by var‐
42       Name  in  sync with the C variable at the address given by addr.  When‐
43       ever the Tcl variable is read the value  of  the  C  variable  will  be
44       returned,  and whenever the Tcl variable is written the C variable will
45       be updated to  have  the  same  value.   Tcl_LinkVar  normally  returns
46       TCL_OK;   if  an  error  occurs while setting up the link (e.g. because
47       varName is the name of array) then TCL_ERROR is returned and the inter‐
48       preter's result contains an error message.
49
50       The  type  argument specifies the type of the C variable, and must have
51       one of the following values, optionally OR'ed with TCL_LINK_READ_ONLY:
52
53       TCL_LINK_INT
54              The C variable is of type int.  Any value written into  the  Tcl
55              variable  must have a proper integer form acceptable to Tcl_Get‐
56              IntFromObj;  attempts to write non-integer values  into  varName
57              will be rejected with Tcl errors.
58
59       TCL_LINK_DOUBLE
60              The  C  variable  is of type double.  Any value written into the
61              Tcl variable must have a proper real form acceptable to Tcl_Get‐
62              DoubleFromObj;   attempts  to write non-real values into varName
63              will be rejected with Tcl errors.
64
65       TCL_LINK_WIDE_INT
66              The C variable is of type Tcl_WideInt (which is an integer  type │
67              at  least  64-bits  wide  on all platforms that can support it.) │
68              Any value written into the Tcl variable must have a proper inte‐ │
69              ger form acceptable to Tcl_GetWideIntFromObj;  attempts to write │
70              non-integer values  into  varName  will  be  rejected  with  Tcl │
71              errors.
72
73       TCL_LINK_BOOLEAN
74              The  C  variable  is  of type int.  If its value is zero then it
75              will read from Tcl as ``0''; otherwise it will read from Tcl  as
76              ``1''.  Whenever varName is modified, the C variable will be set
77              to a 0 or 1 value.  Any value written into the Tcl variable must
78              have  a proper boolean form acceptable to Tcl_GetBooleanFromObj;
79              attempts to  write  non-boolean  values  into  varName  will  be
80              rejected with Tcl errors.
81
82       TCL_LINK_STRING
83              The C variable is of type char *.  If its value is not NULL then │
84              it must be a pointer to a string  allocated  with  Tcl_Alloc  or │
85              ckalloc.   Whenever  the  Tcl variable is modified the current C
86              string will be freed and new memory will be allocated to hold  a
87              copy  of the variable's new value.  If the C variable contains a
88              NULL pointer then the Tcl variable will read as ``NULL''.
89
90       If the TCL_LINK_READ_ONLY flag is present in  type  then  the  variable
91       will  be  read-only  from Tcl, so that its value can only be changed by
92       modifying the C variable.  Attempts to write the variable from Tcl will
93       be rejected with errors.
94
95       Tcl_UnlinkVar removes the link previously set up for the variable given
96       by varName.  If there does not exist a link for varName then the proce‐
97       dure has no effect.
98
99       Tcl_UpdateLinkedVar  may be invoked after the C variable has changed to
100       force the Tcl variable to be updated immediately.  In many  cases  this
101       procedure  is  not  needed,  since any attempt to read the Tcl variable
102       will return the latest value of the C variable.  However,  if  a  trace
103       has  been  set  on the Tcl variable (such as a Tk widget that wishes to
104       display the value of the variable), the trace will not trigger when the
105       C variable has changed.  Tcl_UpdateLinkedVar ensures that any traces on
106       the Tcl variable are invoked.
107
108

KEYWORDS

110       boolean, integer, link, read-only, real, string, traces, variable
111
112
113
114Tcl                                   7.5                       Tcl_LinkVar(3)
Impressum