Next: 3.3.3 Passing Results to/fro
Up: 3.3 Class Tcl
Previous: 3.3.1 Obtain a Reference
3.3.2 Invoking OTcl Procedures
There are four different methods to invoke an OTcl command
through the instance, tcl.
They differ essentially in their calling arguments.
Each function passes a string to the interpreter,
that then evaluates the string in a global context.
These methods will return to the caller if the interpreter returns TCL_OK.
On the other hand, if the interpreter returns TCL_ERROR,
the methods will call tkerror.
The user can overload this procedure to selectively disregard
certain types of errors.
Such intricacies of OTcl programming are outside the
scope of this document.
The next sectionSectionsec:Result
describes methods to access the result returned by the interpreter.
- [char* s]tcl.eval../Tcl/Tcl.ccTcl::eval
invokes []Tcl_GlobalEval to execute s through the interpreter.
- [const char* s]tcl.evalc../Tcl/Tcl.ccTcl::evalc
preserves the argument string s.
It copies the string s into its internal buffer;
it then invokes the previous [char* s]eval on the internal buffer.
- []tcl.eval../Tcl/Tcl.ccTcl::eval
assumes that the command is already stored in the class' internal
bp_; it directly invokes [char* bp_]tcl.eval.
A handle to the buffer itself is available through the method
tcl.buffer../Tcl/Tcl.hTcl::buffer.
-
[const char* s, ...]tcl.evalf../Tcl/Tcl2.ccTcl::evalf
is a Printf(3) like equivalent.
It uses vsprintf(3) internally to create the input string.
As an example, here are some of the ways of using the above methods:
Tcl& tcl = {\bfseries{}Tcl::instance}();
char wrk[128];
strcpy(wrk, "Simulator set NumberInterfaces_ 1");
{\bfseries{}tcl.eval}(wrk);
sprintf({\bfseries{}tcl.buffer}(), "Agent/SRM set requestFunction_ %s", "Fixed");
{\bfseries{}tcl.eval}();
{\bfseries{}tcl.evalc}("puts stdout {hello world}");
{\bfseries{}tcl.evalf}("%s request %d %d", name_, sender, msgid);
Next: 3.3.3 Passing Results to/fro
Up: 3.3 Class Tcl
Previous: 3.3.1 Obtain a Reference
2000-08-24