1Tcl_Eval(3) Tcl Library Procedures Tcl_Eval(3)
2
3
4
5______________________________________________________________________________
6
8 Tcl_EvalObjEx, Tcl_EvalFile, Tcl_EvalObjv, Tcl_Eval, Tcl_EvalEx,
9 Tcl_GlobalEval, Tcl_GlobalEvalObj, Tcl_VarEval, Tcl_VarEvalVA - execute
10 Tcl scripts
11
13 #include <tcl.h>
14
15 int │
16 Tcl_EvalObjEx(interp, objPtr, flags) │
17
18 int │
19 Tcl_EvalFile(interp, fileName) │
20
21 int │
22 Tcl_EvalObjv(interp, objc, objv, flags) │
23
24 int │
25 Tcl_Eval(interp, script) │
26
27 int │
28 Tcl_EvalEx(interp, script, numBytes, flags) │
29
30 int │
31 Tcl_GlobalEval(interp, script) │
32
33 int │
34 Tcl_GlobalEvalObj(interp, objPtr) │
35
36 int │
37 Tcl_VarEval(interp, string, string, ... (char *) NULL) │
38
39 int │
40 Tcl_VarEvalVA(interp, argList) │
41
43 Tcl_Interp *interp (in) │
44 Interpreter in which to execute the │
45 script. The interpreter's result │
46 is modified to hold the result or │
47 error message from the script. │
48
49 Tcl_Obj *objPtr (in) │
50 A Tcl object containing the script │
51 to execute. │
52
53 int flags (in) │
54 ORed combination of flag bits that │
55 specify additional options. │
56 TCL_EVAL_GLOBAL and TCL_EVAL_DIRECT │
57 are currently supported. │
58
59 CONST char *fileName (in) │
60 Name of a file containing a Tcl │
61 script. │
62
63 int objc (in) │
64 The number of objects in the array │
65 pointed to by objPtr; this is also │
66 the number of words in the command. │
67
68 Tcl_Obj **objv (in) │
69 Points to an array of pointers to │
70 objects; each object holds the │
71 value of a single word in the com‐ │
72 mand to execute. │
73
74 int numBytes (in) │
75 The number of bytes in script, not │
76 including any null terminating │
77 character. If -1, then all charac‐ │
78 ters up to the first null byte are │
79 used. │
80
81 CONST char *script (in) │
82 Points to first byte of script to │
83 execute (null-terminated and │
84 UTF-8). │
85
86 char *string (in) │
87 String forming part of a Tcl │
88 script. │
89
90 va_list argList (in) │
91 An argument list which must have │
92 been initialised using │
93 TCL_VARARGS_START, and cleared │
94 using va_end. │
95_________________________________________________________________ │
96
97
99 The procedures described here are invoked to execute Tcl scripts in │
100 various forms. Tcl_EvalObjEx is the core procedure and is used by many │
101 of the others. It executes the commands in the script stored in objPtr │
102 until either an error occurs or the end of the script is reached. If │
103 this is the first time objPtr has been executed, its commands are com‐ │
104 piled into bytecode instructions which are then executed. The byte‐ │
105 codes are saved in objPtr so that the compilation step can be skipped │
106 if the object is evaluated again in the future. │
107
108 The return value from Tcl_EvalObjEx (and all the other procedures │
109 described here) is a Tcl completion code with one of the values TCL_OK, │
110 TCL_ERROR, TCL_RETURN, TCL_BREAK, or TCL_CONTINUE, or possibly some │
111 other integer value originating in an extension. In addition, a result │
112 value or error message is left in interp's result; it can be retrieved │
113 using Tcl_GetObjResult. │
114
115 Tcl_EvalFile reads the file given by fileName and evaluates its con‐ │
116 tents as a Tcl script. It returns the same information as Tcl_EvalOb‐ │
117 jEx. If the file couldn't be read then a Tcl error is returned to │
118 describe why the file couldn't be read. The eofchar for files is '\32' │
119 (^Z) for all platforms. If you require a ``^Z'' in code for string │
120 comparison, you can use ``\032'' or ``\u001a'', which will be safely │
121 substituted by the Tcl interpreter into ``^Z''.
122
123 Tcl_EvalObjv executes a single pre-parsed command instead of a script.
124 The objc and objv arguments contain the values of the words for the Tcl
125 command, one word in each object in objv. Tcl_EvalObjv evaluates the
126 command and returns a completion code and result just like Tcl_EvalOb‐
127 jEx.
128
129 Tcl_Eval is similar to Tcl_EvalObjEx except that the script to be exe‐
130 cuted is supplied as a string instead of an object and no compilation
131 occurs. The string should be a proper UTF-8 string as converted by
132 Tcl_ExternalToUtfDString or Tcl_ExternalToUtf when it is known to pos‐
133 sibly contain upper ASCII characters who's possible combinations might
134 be a UTF-8 special code. The string is parsed and executed directly
135 (using Tcl_EvalObjv) instead of compiling it and executing the byte‐
136 codes. In situations where it is known that the script will never be
137 executed again, Tcl_Eval may be faster than Tcl_EvalObjEx.
138 Tcl_Eval returns a completion code and result just like Tcl_EvalObjEx.
139 Note: for backward compatibility with versions before Tcl 8.0, Tcl_Eval
140 copies the object result in interp to interp->result (use is depre‐
141 cated) where it can be accessed directly.
142 This makes Tcl_Eval somewhat slower than Tcl_EvalEx, which doesn't do
143 the copy.
144
145 Tcl_EvalEx is an extended version of Tcl_Eval that takes additional
146 arguments numBytes and flags. For the efficiency reason given above,
147 Tcl_EvalEx is generally preferred over Tcl_Eval.
148
149 Tcl_GlobalEval and Tcl_GlobalEvalObj are older procedures that are now
150 deprecated. They are similar to Tcl_EvalEx and Tcl_EvalObjEx except
151 that the script is evaluated in the global namespace and its variable
152 context consists of global variables only (it ignores any Tcl proce‐
153 dures that are active). These functions are equivalent to using the
154 TCL_EVAL_GLOBAL flag (see below).
155
156 Tcl_VarEval takes any number of string arguments of any length, con‐
157 catenates them into a single string, then calls Tcl_Eval to execute
158 that string as a Tcl command. It returns the result of the command and
159 also modifies interp->result in the same way as Tcl_Eval. The last
160 argument to Tcl_VarEval must be NULL to indicate the end of arguments.
161 Tcl_VarEval is now deprecated.
162
163 Tcl_VarEvalVA is the same as Tcl_VarEval except that instead of taking
164 a variable number of arguments it takes an argument list. Like
165 Tcl_VarEval, Tcl_VarEvalVA is deprecated.
166
167
169 Any ORed combination of the following values may be used for the flags
170 argument to procedures such as Tcl_EvalObjEx:
171
172 TCL_EVAL_DIRECT This flag is only used by Tcl_EvalObjEx; it is
173 ignored by other procedures. If this flag bit
174 is set, the script is not compiled to bytecodes;
175 instead it is executed directly as is done by
176 Tcl_EvalEx. The TCL_EVAL_DIRECT flag is useful
177 in situations where the contents of an object
178 are going to change immediately, so the byte‐
179 codes won't be reused in a future execution. In
180 this case, it's faster to execute the script
181 directly.
182
183 TCL_EVAL_GLOBAL If this flag is set, the script is processed at
184 global level. This means that it is evaluated
185 in the global namespace and its variable context
186 consists of global variables only (it ignores
187 any Tcl procedures at are active).
188
189
191 During the processing of a Tcl command it is legal to make nested calls
192 to evaluate other commands (this is how procedures and some control
193 structures are implemented). If a code other than TCL_OK is returned
194 from a nested Tcl_EvalObjEx invocation, then the caller should normally
195 return immediately, passing that same return code back to its caller,
196 and so on until the top-level application is reached. A few commands,
197 like for, will check for certain return codes, like TCL_BREAK and
198 TCL_CONTINUE, and process them specially without returning.
199
200 Tcl_EvalObjEx keeps track of how many nested Tcl_EvalObjEx invocations
201 are in progress for interp. If a code of TCL_RETURN, TCL_BREAK, or
202 TCL_CONTINUE is about to be returned from the topmost Tcl_EvalObjEx
203 invocation for interp, it converts the return code to TCL_ERROR and
204 sets interp's result to an error message indicating that the return,
205 break, or continue command was invoked in an inappropriate place. This
206 means that top-level applications should never see a return code from
207 Tcl_EvalObjEx other then TCL_OK or TCL_ERROR.
208
209
211 execute, file, global, object, result, script
212
213
214
215Tcl 8.1 Tcl_Eval(3)