Returning an array from C procedure

From: jacus (jniezgoda_at_kredytbank.pl)
Date: 02/27/04


Date: 27 Feb 2004 06:25:29 -0800

How can I create Tcl array in C procedure,
and how to create this array to Tcl script.
I tried to use Tcl_ObjSetVar2(interp, part1Ptr, part2Ptr, newValuePtr, flags)
but I do not know how to create Tcl_Obj *part1Ptr as Tcl array.

I tried like this:
Tcl_Obj *array = Tcl_NewObj();
Tcl_Obj *index = Tcl_NewStringObj("index_name", -1);
Tcl_Obj *value = Tcl_NewStringObj("element_value", -1);

Tcl_ObjSetVar2(interp, array, index, value, TCL_LEAVE_ERR_MSG);
Tcl_SetObjResult(interp, array);
return TCL_OK;

But it does not work. Any suggestions?



Relevant Pages

  • Traversing TCL array in C
    ... Is there any examples of traversing TCL array in C? ... array back to radius attributes, but don't know how to traverse array ...
    (comp.lang.tcl)
  • Re: returning an element in array
    ... That is not what a Tcl array definition looks like. ... I tried to do this but it is looking for the latest entry only. ... there a way to make it take the first one and look the third field and ...
    (comp.lang.tcl)
  • Re: 2 dimensional arrays
    ... > The actual purpose of my converting a string to Tcl array is I get this ... > big string from my C extension and I want to display it in a Tk Table. ...
    (comp.lang.tcl)
  • Re: 2 dimensional arrays
    ... The actual purpose of my converting a string to Tcl array is I get this ...
    (comp.lang.tcl)
  • Re: NUMA API for Linux
    ... > I don't want to merge the flags the and the mode argument. ... Userspace should be declaring an array of unsigned longs based on the ... If the bits we care about are sane, ...
    (Linux-Kernel)