| 1 |
'\" |
| 2 |
'\" Copyright (c) 1989-1993 The Regents of the University of California. |
| 3 |
'\" Copyright (c) 1994-1997 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 |
.TH Tcl_ExprLong 3 7.0 Tcl "Tcl Library Procedures" |
| 9 |
.so man.macros |
| 10 |
.BS |
| 11 |
.SH NAME |
| 12 |
Tcl_ExprLong, Tcl_ExprDouble, Tcl_ExprBoolean, Tcl_ExprString \- evaluate an expression |
| 13 |
.SH SYNOPSIS |
| 14 |
.nf |
| 15 |
\fB#include <tcl.h>\fR |
| 16 |
.sp |
| 17 |
int |
| 18 |
\fBTcl_ExprLong\fR(\fIinterp, expr, longPtr\fR) |
| 19 |
.sp |
| 20 |
int |
| 21 |
\fBTcl_ExprDouble\fR(\fIinterp, expr, doublePtr\fR) |
| 22 |
.sp |
| 23 |
int |
| 24 |
\fBTcl_ExprBoolean\fR(\fIinterp, expr, booleanPtr\fR) |
| 25 |
.sp |
| 26 |
int |
| 27 |
\fBTcl_ExprString\fR(\fIinterp, expr\fR) |
| 28 |
.SH ARGUMENTS |
| 29 |
.AS Tcl_Interp *booleanPtr out |
| 30 |
.AP Tcl_Interp *interp in |
| 31 |
Interpreter in whose context to evaluate \fIexpr\fR. |
| 32 |
.AP "const char" *expr in |
| 33 |
Expression to be evaluated. |
| 34 |
.AP long *longPtr out |
| 35 |
Pointer to location in which to store the integer value of the |
| 36 |
expression. |
| 37 |
.AP int *doublePtr out |
| 38 |
Pointer to location in which to store the floating-point value of the |
| 39 |
expression. |
| 40 |
.AP int *booleanPtr out |
| 41 |
Pointer to location in which to store the 0/1 boolean value of the |
| 42 |
expression. |
| 43 |
.BE |
| 44 |
|
| 45 |
.SH DESCRIPTION |
| 46 |
.PP |
| 47 |
These four procedures all evaluate the expression |
| 48 |
given by the \fIexpr\fR argument |
| 49 |
and return the result in one of four different forms. |
| 50 |
The expression can have any of the forms accepted by the \fBexpr\fR command. |
| 51 |
Note that these procedures have been largely replaced by the |
| 52 |
value-based procedures \fBTcl_ExprLongObj\fR, \fBTcl_ExprDoubleObj\fR, |
| 53 |
\fBTcl_ExprBooleanObj\fR, and \fBTcl_ExprObj\fR. |
| 54 |
Those value-based procedures evaluate an expression held in a Tcl value |
| 55 |
instead of a string. |
| 56 |
The value argument can retain an internal representation |
| 57 |
that is more efficient to execute. |
| 58 |
.PP |
| 59 |
The \fIinterp\fR argument refers to an interpreter used to |
| 60 |
evaluate the expression (e.g. for variables and nested Tcl |
| 61 |
commands) and to return error information. |
| 62 |
.PP |
| 63 |
For all of these procedures the return value is a standard |
| 64 |
Tcl result: \fBTCL_OK\fR means the expression was successfully |
| 65 |
evaluated, and \fBTCL_ERROR\fR means that an error occurred while |
| 66 |
evaluating the expression. |
| 67 |
If \fBTCL_ERROR\fR is returned then |
| 68 |
the interpreter's result will hold a message describing the error. |
| 69 |
If an error occurs while executing a Tcl command embedded in |
| 70 |
the expression then that error will be returned. |
| 71 |
.PP |
| 72 |
If the expression is successfully evaluated, then its value is |
| 73 |
returned in one of four forms, depending on which procedure |
| 74 |
is invoked. |
| 75 |
\fBTcl_ExprLong\fR stores an integer value at \fI*longPtr\fR. |
| 76 |
If the expression's actual value is a floating-point number, |
| 77 |
then it is truncated to an integer. |
| 78 |
If the expression's actual value is a non-numeric string then |
| 79 |
an error is returned. |
| 80 |
.PP |
| 81 |
\fBTcl_ExprDouble\fR stores a floating-point value at \fI*doublePtr\fR. |
| 82 |
If the expression's actual value is an integer, it is converted to |
| 83 |
floating-point. |
| 84 |
If the expression's actual value is a non-numeric string then |
| 85 |
an error is returned. |
| 86 |
.PP |
| 87 |
\fBTcl_ExprBoolean\fR stores a 0/1 integer value at \fI*booleanPtr\fR. |
| 88 |
If the expression's actual value is an integer or floating-point |
| 89 |
number, then they store 0 at \fI*booleanPtr\fR if |
| 90 |
the value was zero and 1 otherwise. |
| 91 |
If the expression's actual value is a non-numeric string then |
| 92 |
it must be one of the values accepted by \fBTcl_GetBoolean\fR |
| 93 |
such as |
| 94 |
.QW yes |
| 95 |
or |
| 96 |
.QW no , |
| 97 |
or else an error occurs. |
| 98 |
.PP |
| 99 |
\fBTcl_ExprString\fR returns the value of the expression as a |
| 100 |
string stored in the interpreter's result. |
| 101 |
|
| 102 |
.SH "SEE ALSO" |
| 103 |
Tcl_ExprLongObj, Tcl_ExprDoubleObj, Tcl_ExprBooleanObj, Tcl_ExprObj |
| 104 |
|
| 105 |
.SH KEYWORDS |
| 106 |
boolean, double, evaluate, expression, integer, value, string |