Passing string from Tcl to C 
Author Message
 Passing string from Tcl to C

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)

error = Tcl_GetDoubleFromObj (interp, objv[3], &salary);

or

if (error == TCL_OK)

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);

Cheers,

Ahmed



Mon, 22 Dec 2003 12:58:58 GMT  
 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



Mon, 22 Dec 2003 14:43:01 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. passing a prolog string to tcl and unbalanced braces

2. unbalanced braces when passing a prolog string to tcl

3. to CS: or not to CS: in F-PC assembler

4. DEPRECATED: http://www.cs.uoregon.edu/research/tcl/

5. PATCHES: Patch Archive Updated http://www.cs.uoregon.edu/research/tcl/patch/

6. Tcl 7.3 pass infor to Tcl 8.0

7. Tcl Gurus: Help passing Varibles from C to Tcl

8. Tcl strings to C strings

9. Tcl strings to C strings

10. Passing String to AppleScript

11. Passing string to OCX method - problem

12. Passing strings by address.

 

 
Powered by phpBB® Forum Software