i register the command like that
Tcl_Obj *tclresult = Tcl_NewStringObj(".c itemconfigure ::cnv -text",
-1);
i register the value like that
Tcl_Obj *tot = Tcl_NewIntObj(0);
and i can eval it with :
Tcl_AppendObjToObj(tclresult, tot);
Tcl_EvalObjEx(interp, tclresult, TCL_EVAL_DIRECT);
here's my question:
in a C loop, i change the value of an int obj pointer with:
Tcl_SetIntObj(tot, (j-1));
am i obliged to invoke Tcl_AppendObjToObj + Tcl_EvalObjEx in the loop
to update the value, or is there's another way ?
hope to be clear enough...
best regards
nicolas
This copies the string representation of tot to tclresult. The objects
are unconnected after the copy. Subsequent changes to tot do not change
tclresult.
# am i obliged to invoke Tcl_AppendObjToObj + Tcl_EvalObjEx in the loop
# to update the value, or is there's another way ?
You can sometimes get away with changing a list element's value without
the knowledge of the list object, but Tcl objects are designed to prevent
this, and will make it as difficult as possible to get away with.
In other structured value systems, often a value is an individually
addressable entity which can be changed independently of any value
containing it. Tcl insteads maintains the illusion that each structured
value is separately copied into containing values.
For example,
set L1 {a b {c d e} f}
set L2 [lrange $L1 1 end]
It possible that L1 and L2 actually internally have the same Tcl_Obj*
list elements b, {c d e}, and f. However you cannot exploit those shared
values with Tcl code, or C code that obeys the rules
lset L2 1 1 x
b {c x e} f
set L1
a b {c d e} f
--
SM Ryan http://www.rawbw.com/~wyrmwif/
I'm not even supposed to be here today.
it's a shame
Look at Tcl_EvalObjv in http://www.tcl.tk/man/tcl8.4/TclLib/Eval.htm
Using it, you'd do something like:
Tcl_Obj* command[5];
command[0] = Tcl_NewStringObj(".c", -1);
Tcl_IncrRefCount(command[0]);
command[1] = Tcl_NewStringObj("itemconfigure", -1);
Tcl_IncrRefCount(command[1]);
command[2] = Tcl_NewStringObj("::cnv", -1);
Tcl_IncrRefCount(command[2]);
command[3] = Tcl_NewStringObj("-text", -1);
Tcl_IncrRefCount(command[3]);
command[4] = Tcl_NewObj();
Tcl_IncrRefCount(command[4]);
... and then later on, when you've got your total
Tcl_SetIntObj(command[4], (j-i)); /* from your example */
Tcl_EvalObjv(interp, 5, objv, TCL_EVAL_GLOBAL);
I think that the combination I described does what you want.
You could also do it by holding a reference to a Tcl_Obj
containing a list and doing Tcl_ListObjSetElement on it.
If you use this technique, be very careful about reference
counting.
--
73 de ke9tv/2, Kevin