4 #include "chiark-tcl-base.h"
6 void cht_scriptinv_init(ScriptToInvoke *si) {
11 void cht_scriptinv_cancel(ScriptToInvoke *si) {
12 if (si->obj) { Tcl_DecrRefCount(si->obj); si->obj= 0; }
13 if (si->xargs) { Tcl_DecrRefCount(si->xargs); si->xargs= 0; }
16 int cht_scriptinv_set(ScriptToInvoke *si, Tcl_Interp *ip,
17 Tcl_Obj *newscript, Tcl_Obj *xargs) {
20 cht_scriptinv_cancel(si);
22 rc= Tcl_ListObjLength(ip, newscript, &si->llength); if (rc) return rc;
23 Tcl_IncrRefCount(newscript);
26 rc= Tcl_ListObjLength(ip, xargs, &xlength); if (rc) return rc;
27 Tcl_IncrRefCount(xargs);
28 si->llength += xlength;
37 void cht_scriptinv_invoke(ScriptToInvoke *si, int argc, Tcl_Obj *const *argv) {
42 for (i=0; i<argc; i++) Tcl_IncrRefCount(argv[i]);
44 invoke= Tcl_DuplicateObj(si->obj);
45 Tcl_IncrRefCount(invoke);
48 rc= Tcl_ListObjAppendList(si->ip, invoke, si->xargs);
52 rc= Tcl_ListObjReplace(si->ip, invoke,si->llength,0, argc,argv);
55 rc= Tcl_EvalObjEx(si->ip,invoke,TCL_EVAL_GLOBAL|TCL_EVAL_DIRECT);
61 for (i=0; i<argc; i++) Tcl_DecrRefCount(argv[i]);
62 if (invoke) Tcl_DecrRefCount(invoke);
63 if (rc) Tcl_BackgroundError(si->ip);