
Passing string from Tcl to C
Quote:
>Hi,
>I am trying to extend Tcl, so I have this command that will contain the name
>of the command and some arguments. Some of the arguments are numbers but
>some are not numbers and they maybe 50 byte long so when I am in the DLL
>file I will do the following to assign some of these arguments to some
>variables. Example:
>double salary;
>int cnt;
>Tcl_Obj *Name;
>if (error == TCL_OK)
should this actually be error!=TCL_OK
Quote:
>error = Tcl_GetDoubleFromObj (interp, objv[3], &salary);
>or
>if (error == TCL_OK)
should this actually be error!=TCL_OK
Quote:
>error = Tcl_GetIntFromObj (interp, objv[3], &cnt);
>the problem is how would I be able to assign the data or the string to a
>pointer of Tcl_Obj type
>I tried the following but it didn't work.
>if (error == TCL_OK)
>error = Tcl_GetStringFromObj (interp, objv[1], Name);
if you want to extract the string characters
stringpointer = Tcl_GetStringFromObj(objv[1],&length);
this always succeeds (or generates an address fault) so no TCL_OK or
TCL_ERROR is returned
its always TCL_OK
if you want to replace the value of an object
Tcl_SetStringResult(obj,stringpointer, length or -1)
but you should check if Tcl_IsShared(obj) firsdt because it is bad karma
to change values co-owners of the object think are invariant