1 | '\" |
---|
2 | '\" Copyright (c) 1993 The Regents of the University of California. |
---|
3 | '\" Copyright (c) 1994-1996 Sun Microsystems, Inc. |
---|
4 | '\" |
---|
5 | '\" See the file "license.terms" for information on usage and redistribution |
---|
6 | '\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
---|
7 | '\" |
---|
8 | '\" RCS: @(#) $Id: LinkVar.3,v 1.16 2007/12/13 15:22:31 dgp Exp $ |
---|
9 | '\" |
---|
10 | .so man.macros |
---|
11 | .TH Tcl_LinkVar 3 7.5 Tcl "Tcl Library Procedures" |
---|
12 | .BS |
---|
13 | .SH NAME |
---|
14 | Tcl_LinkVar, Tcl_UnlinkVar, Tcl_UpdateLinkedVar \- link Tcl variable to C variable |
---|
15 | .SH SYNOPSIS |
---|
16 | .nf |
---|
17 | \fB#include <tcl.h>\fR |
---|
18 | .sp |
---|
19 | int |
---|
20 | \fBTcl_LinkVar\fR(\fIinterp, varName, addr, type\fR) |
---|
21 | .sp |
---|
22 | \fBTcl_UnlinkVar\fR(\fIinterp, varName\fR) |
---|
23 | .sp |
---|
24 | \fBTcl_UpdateLinkedVar\fR(\fIinterp, varName\fR) |
---|
25 | .SH ARGUMENTS |
---|
26 | .AS Tcl_Interp writable |
---|
27 | .AP Tcl_Interp *interp in |
---|
28 | Interpreter that contains \fIvarName\fR. |
---|
29 | Also used by \fBTcl_LinkVar\fR to return error messages. |
---|
30 | .AP "const char" *varName in |
---|
31 | Name of global variable. |
---|
32 | .AP char *addr in |
---|
33 | Address of C variable that is to be linked to \fIvarName\fR. |
---|
34 | .AP int type in |
---|
35 | Type of C variable. Must be one of \fBTCL_LINK_INT\fR, |
---|
36 | .VS 8.5 |
---|
37 | \fBTCL_LINK_UINT\fR, \fBTCL_LINK_CHAR\fR, \fBTCL_LINK_UCHAR\fR, |
---|
38 | \fBTCL_LINK_SHORT\fR, \fBTCL_LINK_USHORT\fR, \fBTCL_LINK_LONG\fR, |
---|
39 | \fBTCL_LINK_ULONG\fR, |
---|
40 | .VE 8.5 |
---|
41 | \fBTCL_LINK_WIDE_INT\fR, |
---|
42 | .VS 8.5 |
---|
43 | \fBTCL_LINK_WIDE_UINT\fR, \fBTCL_LINK_FLOAT\fR, |
---|
44 | .VE 8.5 |
---|
45 | \fBTCL_LINK_DOUBLE\fR, \fBTCL_LINK_BOOLEAN\fR, or |
---|
46 | \fBTCL_LINK_STRING\fR, optionally OR'ed with \fBTCL_LINK_READ_ONLY\fR |
---|
47 | to make Tcl variable read-only. |
---|
48 | .BE |
---|
49 | |
---|
50 | .SH DESCRIPTION |
---|
51 | .PP |
---|
52 | \fBTcl_LinkVar\fR uses variable traces to keep the Tcl variable |
---|
53 | named by \fIvarName\fR in sync with the C variable at the address |
---|
54 | given by \fIaddr\fR. |
---|
55 | Whenever the Tcl variable is read the value of the C variable will |
---|
56 | be returned, and whenever the Tcl variable is written the C |
---|
57 | variable will be updated to have the same value. |
---|
58 | \fBTcl_LinkVar\fR normally returns \fBTCL_OK\fR; if an error occurs |
---|
59 | while setting up the link (e.g. because \fIvarName\fR is the |
---|
60 | name of array) then \fBTCL_ERROR\fR is returned and the interpreter's result |
---|
61 | contains an error message. |
---|
62 | .PP |
---|
63 | The \fItype\fR argument specifies the type of the C variable, |
---|
64 | and must have one of the following values, optionally OR'ed with |
---|
65 | \fBTCL_LINK_READ_ONLY\fR: |
---|
66 | .TP |
---|
67 | \fBTCL_LINK_INT\fR |
---|
68 | The C variable is of type \fBint\fR. |
---|
69 | Any value written into the Tcl variable must have a proper integer |
---|
70 | form acceptable to \fBTcl_GetIntFromObj\fR; attempts to write |
---|
71 | non-integer values into \fIvarName\fR will be rejected with |
---|
72 | Tcl errors. |
---|
73 | .VS 8.5 |
---|
74 | .TP |
---|
75 | \fBTCL_LINK_UINT\fR |
---|
76 | The C variable is of type \fBunsigned int\fR. |
---|
77 | Any value written into the Tcl variable must have a proper unsigned |
---|
78 | integer form acceptable to \fBTcl_GetWideIntFromObj\fR and in the |
---|
79 | platform's defined range for the \fBunsigned int\fR type; attempts to |
---|
80 | write non-integer values (or values outside the range) into |
---|
81 | \fIvarName\fR will be rejected with Tcl errors. |
---|
82 | .TP |
---|
83 | \fBTCL_LINK_CHAR\fR |
---|
84 | The C variable is of type \fBchar\fR. |
---|
85 | Any value written into the Tcl variable must have a proper integer |
---|
86 | form acceptable to \fBTcl_GetIntFromObj\fR and be in the range of the |
---|
87 | \fBchar\fR datatype; attempts to write non-integer or out-of-range |
---|
88 | values into \fIvarName\fR will be rejected with Tcl errors. |
---|
89 | .TP |
---|
90 | \fBTCL_LINK_UCHAR\fR |
---|
91 | The C variable is of type \fBunsigned char\fR. |
---|
92 | Any value written into the Tcl variable must have a proper unsigned |
---|
93 | integer form acceptable to \fBTcl_GetIntFromObj\fR and in the |
---|
94 | platform's defined range for the \fBunsigned char\fR type; attempts to |
---|
95 | write non-integer values (or values outside the range) into |
---|
96 | \fIvarName\fR will be rejected with Tcl errors. |
---|
97 | .TP |
---|
98 | \fBTCL_LINK_SHORT\fR |
---|
99 | The C variable is of type \fBshort\fR. |
---|
100 | Any value written into the Tcl variable must have a proper integer |
---|
101 | form acceptable to \fBTcl_GetIntFromObj\fR and be in the range of the |
---|
102 | \fBshort\fR datatype; attempts to write non-integer or out-of-range |
---|
103 | values into \fIvarName\fR will be rejected with Tcl errors. |
---|
104 | .TP |
---|
105 | \fBTCL_LINK_USHORT\fR |
---|
106 | The C variable is of type \fBunsigned short\fR. |
---|
107 | Any value written into the Tcl variable must have a proper unsigned |
---|
108 | integer form acceptable to \fBTcl_GetIntFromObj\fR and in the |
---|
109 | platform's defined range for the \fBunsigned short\fR type; attempts to |
---|
110 | write non-integer values (or values outside the range) into |
---|
111 | \fIvarName\fR will be rejected with Tcl errors. |
---|
112 | .TP |
---|
113 | \fBTCL_LINK_LONG\fR |
---|
114 | The C variable is of type \fBlong\fR. |
---|
115 | Any value written into the Tcl variable must have a proper integer |
---|
116 | form acceptable to \fBTcl_GetLongFromObj\fR; attempts to write |
---|
117 | non-integer or out-of-range |
---|
118 | values into \fIvarName\fR will be rejected with Tcl errors. |
---|
119 | .TP |
---|
120 | \fBTCL_LINK_ULONG\fR |
---|
121 | The C variable is of type \fBunsigned long\fR. |
---|
122 | Any value written into the Tcl variable must have a proper unsigned |
---|
123 | integer form acceptable to \fBTcl_GetWideIntFromObj\fR and in the |
---|
124 | platform's defined range for the \fBunsigned long\fR type; attempts to |
---|
125 | write non-integer values (or values outside the range) into |
---|
126 | \fIvarName\fR will be rejected with Tcl errors. |
---|
127 | .VE 8.5 |
---|
128 | .TP |
---|
129 | \fBTCL_LINK_DOUBLE\fR |
---|
130 | The C variable is of type \fBdouble\fR. |
---|
131 | Any value written into the Tcl variable must have a proper real |
---|
132 | form acceptable to \fBTcl_GetDoubleFromObj\fR; attempts to write |
---|
133 | non-real values into \fIvarName\fR will be rejected with |
---|
134 | Tcl errors. |
---|
135 | .VS 8.5 |
---|
136 | .TP |
---|
137 | \fBTCL_LINK_FLOAT\fR |
---|
138 | The C variable is of type \fBfloat\fR. |
---|
139 | Any value written into the Tcl variable must have a proper real |
---|
140 | form acceptable to \fBTcl_GetDoubleFromObj\fR and must be within the |
---|
141 | range acceptable for a \fBfloat\fR; attempts to |
---|
142 | write non-real values (or values outside the range) into |
---|
143 | \fIvarName\fR will be rejected with Tcl errors. |
---|
144 | .VE 8.5 |
---|
145 | .TP |
---|
146 | \fBTCL_LINK_WIDE_INT\fR |
---|
147 | The C variable is of type \fBTcl_WideInt\fR (which is an integer type |
---|
148 | at least 64-bits wide on all platforms that can support it.) |
---|
149 | Any value written into the Tcl variable must have a proper integer |
---|
150 | form acceptable to \fBTcl_GetWideIntFromObj\fR; attempts to write |
---|
151 | non-integer values into \fIvarName\fR will be rejected with |
---|
152 | Tcl errors. |
---|
153 | .VS 8.5 |
---|
154 | .TP |
---|
155 | \fBTCL_LINK_WIDE_UINT\fR |
---|
156 | The C variable is of type \fBTcl_WideUInt\fR (which is an unsigned |
---|
157 | integer type at least 64-bits wide on all platforms that can support |
---|
158 | it.) |
---|
159 | Any value written into the Tcl variable must have a proper unsigned |
---|
160 | integer form acceptable to \fBTcl_GetWideIntFromObj\fR (it will be |
---|
161 | cast to unsigned); |
---|
162 | .\" FIXME! Use bignums instead. |
---|
163 | attempts to write non-integer values into \fIvarName\fR will be |
---|
164 | rejected with Tcl errors. |
---|
165 | .VE 8.5 |
---|
166 | .TP |
---|
167 | \fBTCL_LINK_BOOLEAN\fR |
---|
168 | The C variable is of type \fBint\fR. |
---|
169 | If its value is zero then it will read from Tcl as |
---|
170 | .QW 0 ; |
---|
171 | otherwise it will read from Tcl as |
---|
172 | .QW 1 . |
---|
173 | Whenever \fIvarName\fR is |
---|
174 | modified, the C variable will be set to a 0 or 1 value. |
---|
175 | Any value written into the Tcl variable must have a proper boolean |
---|
176 | form acceptable to \fBTcl_GetBooleanFromObj\fR; attempts to write |
---|
177 | non-boolean values into \fIvarName\fR will be rejected with |
---|
178 | Tcl errors. |
---|
179 | .TP |
---|
180 | \fBTCL_LINK_STRING\fR |
---|
181 | The C variable is of type \fBchar *\fR. |
---|
182 | If its value is not NULL then it must be a pointer to a string |
---|
183 | allocated with \fBTcl_Alloc\fR or \fBckalloc\fR. |
---|
184 | Whenever the Tcl variable is modified the current C string will be |
---|
185 | freed and new memory will be allocated to hold a copy of the variable's |
---|
186 | new value. |
---|
187 | If the C variable contains a NULL pointer then the Tcl variable |
---|
188 | will read as |
---|
189 | .QW NULL . |
---|
190 | .PP |
---|
191 | If the \fBTCL_LINK_READ_ONLY\fR flag is present in \fItype\fR then the |
---|
192 | variable will be read-only from Tcl, so that its value can only be |
---|
193 | changed by modifying the C variable. |
---|
194 | Attempts to write the variable from Tcl will be rejected with errors. |
---|
195 | .PP |
---|
196 | \fBTcl_UnlinkVar\fR removes the link previously set up for the |
---|
197 | variable given by \fIvarName\fR. If there does not exist a link |
---|
198 | for \fIvarName\fR then the procedure has no effect. |
---|
199 | .PP |
---|
200 | \fBTcl_UpdateLinkedVar\fR may be invoked after the C variable has |
---|
201 | changed to force the Tcl variable to be updated immediately. |
---|
202 | In many cases this procedure is not needed, since any attempt to |
---|
203 | read the Tcl variable will return the latest value of the C variable. |
---|
204 | However, if a trace has been set on the Tcl variable (such as a |
---|
205 | Tk widget that wishes to display the value of the variable), the |
---|
206 | trace will not trigger when the C variable has changed. |
---|
207 | \fBTcl_UpdateLinkedVar\fR ensures that any traces on the Tcl |
---|
208 | variable are invoked. |
---|
209 | |
---|
210 | .SH KEYWORDS |
---|
211 | boolean, integer, link, read-only, real, string, traces, variable |
---|