- Tcl_EvalObj, Tcl_EvalFile, Tcl_EvalObjv, Tcl_Eval, Tcl_Eval2, Tcl_GlobalEval, Tcl_VarEval - execute Tcl scripts
- FLAG BITS
- MISCELLANEOUS DETAILS
Tcl_EvalObj, Tcl_EvalFile, Tcl_EvalObjv, Tcl_Eval, Tcl_Eval2, Tcl_GlobalEval, Tcl_VarEval - execute Tcl scripts
Tcl_EvalObj(interp, objPtr, flags)
Tcl_EvalObjv(interp, objc, objv, command, numBytes, flags)
Tcl_Eval2(interp, script, numBytes, flags)
Tcl_VarEval(interp, string, string, ... (char *) NULL)
The procedures described here are invoked to execute Tcl scripts in
Tcl_EvalObj is the core procedure and is used by many of the others.
It executes the commands in the script stored in objPtr
until either an error occurs or the end of the script is reached.
If this is the first time objPtr has been executed,
its commands are compiled into bytecode instructions
which are then executed. The
bytecodes are saved in objPtr so that the compilation step
can be skipped if the object is evaluated again in the future.
- Tcl_Interp *interp (in)
Interpreter in which to execute the script. The interpreter's result is
modified to hold the result or error message from the script.
- Tcl_Obj *objPtr (in)
A Tcl object containing the script to execute.
- int flags (in)
ORed combination of flag bits that specify additional options.
TCL_EVAL_GLOBAL and TCL_EVAL_DIRECT are currently supported.
- char *fileName (in)
Name of a file containing a Tcl script.
- int *objc (in)
The number of objects in the array pointed to by objPtr;
this is also the number of words in the command.
- Tcl_Obj **objv (in)
Points to an array of pointers to objects; each object holds the
value of a single word in the command to execute.
- char *command (in)
Points to the beginning of the string representation of the
command, if there is one. If the string representation of the
command is unknown then an empty string should be supplied.
This information is used for command tracing.
- int numBytes (in)
The number of bytes in command or script, not including any
null terminating character. If -1, then all characters up to the
first null byte are used.
- char *script (in)
Points to first byte of script to execute. This script must be in
writable memory: temporary modifications are made to it during
- char *string (in)
String forming part of a Tcl script.
The return value from Tcl_EvalObj (and all the other procedures
described here) is a Tcl completion code with
one of the values TCL_OK, TCL_ERROR, TCL_RETURN,
TCL_BREAK, or TCL_CONTINUE.
In addition, a result value or error message is left in interp's
result; it can be retrieved using Tcl_GetObjResult.
Tcl_EvalFile reads the file given by fileName and evaluates
its contents as a Tcl script. It returns the same information as
If the file couldn't be read then a Tcl error is returned to describe
why the file couldn't be read.
Tcl_EvalObjv executes a single pre-parsed command instead of a
script. The objc and objv arguments contain the values
of the words for the Tcl command, one word in each object in
objv. Tcl_EvalObjv evaluates the command and returns
a completion code and result just like Tcl_EvalObj.
The command argument is used only to provide contextual information
to command traces. Note: unlike the other procedures described here,
Tcl_EvalObjv does not add any information to the errorInfo
variable after an error. It is up to the caller to do this, if it
Tcl_Eval is similar to Tcl_EvalObj except that
the script to be executed is supplied as a string instead of an
object and no compilation occurs. The string is parsed and executed
directly (using Tcl_EvalObjv) instead of compiling it and
executing the bytecodes. In situations where it is known that the
script will never be executed again, Tcl_Eval may be
faster than Tcl_EvalObj. Tcl_Eval returns a completion
code and result just like Tcl_EvalObj. Note: for backward
compatibility with versions before Tcl 8.0, Tcl_Eval
copies the object result in interp to interp->result
where it can be accessed directly. This makes Tcl_Eval somewhat
slower than Tcl_Eval2, which doesn't do the copy.
Tcl_Eval2 is an extended version of Tcl_Eval that takes
additional arguments numBytes and flags. For the
efficiency reason given above, Tcl_Eval2 is generally preferred
Tcl_GlobalEval is an older procedure that is now deprecated.
It is similar to Tcl_Eval except that the script is evaluated in
the global namespace and its variable context consists of global
variables only (it ignores any Tcl procedures that are active).
Like Tcl_Eval, it leaves a null-terminated
string version of the result in interp->result where it can
be accessed directly.
Tcl_VarEval takes any number of string arguments
of any length, concatenates them into a single string,
then calls Tcl_Eval to execute that string as a Tcl command.
It returns the result of the command and also modifies
interp->result in the same way as Tcl_Eval.
The last argument to Tcl_VarEval must be NULL to indicate the end
of arguments. Tcl_VarEval is now deprecated.
Any ORed combination of the following values may be used for the
flags argument to procedures such as Tcl_EvalObj:
During the processing of a Tcl command it is legal to make nested
calls to evaluate other commands (this is how procedures and
some control structures are implemented).
If a code other than TCL_OK is returned
from a nested Tcl_EvalObj invocation,
then the caller should normally return immediately,
passing that same return code back to its caller,
and so on until the top-level application is reached.
A few commands, like for, will check for certain
return codes, like TCL_BREAK and TCL_CONTINUE, and process them
specially without returning.
This flag is only used by Tcl_EvalObj; it is ignored by
other procedures. If this flag bit is set, the script is not
compiled to bytecodes; instead it is executed directly
as is done by Tcl_Eval2. The
TCL_EVAL_DIRECT flag is useful in situations where the
contents of an object are going to change immediately, so the
bytecodes won't be reused in a future execution. In this case,
it's faster to execute the script directly.
If this flag is set, the script is processed at global level. This
means that it is evaluated in the global namespace and its variable
context consists of global variables only (it ignores any Tcl
procedures at are active).
Tcl_EvalObj keeps track of how many nested Tcl_EvalObj
invocations are in progress for interp.
If a code of TCL_RETURN, TCL_BREAK, or TCL_CONTINUE is
about to be returned from the topmost Tcl_EvalObj
invocation for interp,
it converts the return code to TCL_ERROR
and sets interp's result to an error message indicating that
the return, break, or continue command was
invoked in an inappropriate place.
This means that top-level applications should never see a return code
from Tcl_EvalObj other then TCL_OK or TCL_ERROR.
execute, file, global, object, result, script
Copyright © 1989-1993 The Regents of the University of California.
Copyright © 1994-1997 Sun Microsystems, Inc.
Copyright © 1995-1997 Roger E. Critchlow Jr.