In a message dated 8/30/01 12:00:42 PM Eastern Daylight Time,
[EMAIL PROTECTED] writes:


If I've got a detached thread running some C code, how might I go about
executing a Tcl procedure.  Ns_TclEval looks like what I'm looking for, but
it needs a server connection (as far as I can tell from the documentation).
If anyone has done this before, or could give me some pointers/examples it'd
be much appreciated.


You could use Tcl_Eval. If you have a detached thread, then you have a Tcl
interpreter (the one calling the C). You could pass that interp pointer to
Tcl_Eval as shown below.


NOTE: completely untested code (that has no error checking):


MyTclCmd(ClientData unused, Tcl_Interp * interp, int argc, char **argv)
{
    Tcl_DString tclscript;

    /* assuming in this example that argv[1] is the tcl script */

    Tcl_DStringInit(&tclscript);
    Tcl_DStringAppend(&tclscript, argv[1], strlen(argv[1]));

    if (Tcl_Eval(interp,  tclscript.string) != TCL_OK) {
        /* handle the error */
        Ns_TclLogError(interp);
    } else {
       /* handle result, if wanted, which is in interp->result */
       ...
    }

    Tcl_DStringFree(&tclscript);
}


-- michael

___________________
 michael richman
 sr. software engineer
 aol technologies - local
 214.954.6204

Reply via email to