Le lundi 5 juin 2023 à 17:05:22 UTC+2,
clt.to...@dfgh.net a écrit :
> Create the list this way:
> set myList [list 1 2 3 4 [::oo::Obj10 get] foo 10 bar]
@Rich ,
I can't, the goal here is to check each type, so I need to keep the name of the object.
@Dave
If I understand , In that way so in Tcl :
foreach obj $myList {
if {![catch {$obj get} value]} {
# Do something
}
}
Maybe I'm wrong but in pure Tcl, I would never do like that, It's maybe different in C.
That said
Below my C code :
Tcl_Obj* cmd[2];
cmd[1] = Tcl_NewStringObj ("get", -1);
Tcl_IncrRefCount(cmd[1]);
for (int i = 0; i < count; ++i) {
cmd[0] = sub_elements[i];
Tcl_IncrRefCount(cmd[0]);
if (Tcl_EvalObjv(interp, 2, cmd, 0) == TCL_OK) {
Tcl_DecrRefCount(cmd[0]);
Tcl_ListObjAppendElement(interp, data, Tcl_GetObjResult(interp));
} else {
// Do something...
}
}
Tcl_DecrRefCount(cmd[1]);
I’m not sure about myself, it works , but I tested on a list of 20000 items and my performance is bad, my C code is correct ?
Thanks
Nicolas