使用lindex命令可以相当容易地访问TCL列表中的子元素.以下是我的 list :
set myList {Y {FUNCTION {{KEY1 KEY2 KEY3}}}}
我的目标是能够检索此子列表:
KEY1 KEY2 KEY3.
Side Tcl, with lindex
command I can do that : lindex $myList {1 1 0}
.
With Tcl C API, I think I need to use this function Tcl_ListObjIndex, but it doesn't allow you to add several indexes to select elements from sublists.
Here's my C code :
Tcl_Obj* first_list = Tcl_NewObj();
Tcl_Obj* sub_list = Tcl_NewObj();
Tcl_Obj* subsub_list = Tcl_NewObj();
Tcl_ListObjIndex(interp, myList, 1, &first_list);
Tcl_ListObjIndex(interp, first_list, 1, &sub_list);
Tcl_ListObjIndex(interp, sub_list, 0, &subsub_list);
return subsub_list;
它起作用了,但我刚刚试着把我的Tcl
代码翻译成C
代码,我不知道这是非常有效还是正确的.