next up previous contents index
Next: 3.3.4 Error Reporting and Up: 3.3 Class Tcl Previous: 3.3.2 Invoking OTcl Procedures

3.3.3 Passing Results to/fro the Interpreter

When the interpreter invokes a C++ method, it expects the result back in the private member variable, tcl_-result. Two methods are available to set this variable.

[const char* s]tcl.result../Tcl/Tcl.hTcl::result

Pass the result string s back to the interpreter.

[const char* fmt, ...]tcl.resultf../Tcl/Tcl2.ccTcl::resultf

varargs(3) variant of above to format the result using vsprintf(3), pass the result string back to the interpreter.

        if (strcmp(argv[1], "now") == 0) {
                {\bfseries{}tcl.resultf}("%.17g", clock());
                return TCL_OK;
        {\bfseries{}tcl.result}("Invalid operation specified");
        return TCL_ERROR;

Likewise, when a C++ method invokes an OTcl command, the interpreter returns the result in tcl_-result.

tcl.result../Tcl/Tcl.hTcl::result must be used to retrieve the result. Note that the result is a string, that must be converted into an internal format appropriate to the type of result.
        tcl.evalc("Simulator set NumberInterfaces_");
        char* ni = {\bfseries{}tcl.result}();
        if (atoi(ni) != 1)
                tcl.evalc("Simulator set NumberInterfaces_ 1");