crossing boundaries into Tcl

David Gravereaux davygrvy at pobox.com
Fri Jun 1 21:50:44 EDT 2001


David Gravereaux <davygrvy at pobox.com> wrote:

>Is there a start token that can return the value of the last operation?  There
>must be somewhere.  The result of an eval is such a central concept to Tcl that
>I find it strange that it's missing in other interpreted languages.
>
>Tcl_Interp *interp;
>
>interp = Tcl_CreateInterp();
>Tcl_Init(interp);
>Tcl_Eval(interp, "pwd");
>printf("Your current working directory is %s", interp->result);
>
>
>What's the same concept when using python embedded?  How do you get the result
>of an operation as a char*?

Actually, the more complete code would be:

Tcl_Interp *interp;
int code;

interp = Tcl_CreateInterp();
code = Tcl_Eval(interp, "proc foo {} {}; expr {rand()}");
if (code == TCL_OK) {
  printf("the random number is %s", interp->result);
} else {
  printf("We bombed with %s", interp->result);
}

If all that PyRun_String() returns is "exception or not", where/how is it
possible to get the last result of the operation?  Is it true that POP_TOP in
eval_code2() of ceval.c discards the object before returning?  How can I not pop
the top, and grab the result then Py_DECREF it after I'm done?
--
David Gravereaux <davygrvy at pobox.com>



More information about the Python-list mailing list