Home > Archive > Tcl > October 2005 > Setting a list variable [C API]
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Setting a list variable [C API]
|
|
| horape@gmail.com 2005-10-28, 3:57 am |
| I wanna to set a list variable from the C side of my app, but it
doesn't work as expected. My code is similar to:
---
#include <tcl.h>
#include <stdio.h>
int main()
{
char *argv[]={"argv0", "argv1"};
int argc=2;
int i;
int r;
Tcl_Interp *interpreter=Tcl_CreateInterp();
Tcl_Obj *ARGV = Tcl_NewListObj(0,0);
for (i=0;i<argc;++i)
Tcl_ListObjAppendElement(interpreter, ARGV,
Tcl_NewStringObj(argv[i], strlen(argv[i])));
if (Tcl_SetVar2Ex(interpreter, "ARGV", "", ARGV,
TCL_GLOBAL_ONLY|TCL_LIST_ELEMENT) == 0) {
printf("oops!\n");
}
Tcl_Eval(interpreter,"puts [llength ARGV]");
Tcl_Eval(interpreter,"puts [lindex ARGV 0]");
Tcl_DeleteInterp(interpreter);
}
---
I expected that this should print:
2
argv0
Instead, it prints:
1
ARGV
Where is my error?
Thanks!
HoraPe
| |
| Aric Bills 2005-10-28, 3:57 am |
| You're missing a couple $ signs.
Aric
| |
| Ronnie Brunner 2005-10-28, 3:57 am |
| horape@gmail.com wrote:
....
>
> if (Tcl_SetVar2Ex(interpreter, "ARGV", "", ARGV,
if (Tcl_SetVar2Ex(interpreter, "ARGV", NULL, ARGV,
> TCL_GLOBAL_ONLY|TCL_LIST_ELEMENT) == 0) {
> printf("oops!\n");
> }
> Tcl_Eval(interpreter,"puts [llength ARGV]");
> Tcl_Eval(interpreter,"puts [lindex ARGV 0]");
Tcl_Eval(interpreter,"puts [llength $ARGV]");
Tcl_Eval(interpreter,"puts [lindex $ARGV 0]");
> Tcl_DeleteInterp(interpreter);
> }
....
Two missing '$' and a NULL ponter instead of a "" ...
Tcl_Eval(interpreter,"puts [llength $ARGV]");
Tcl_Eval(interpreter,"puts [lindex $ARGV 0]");
----------------------------------------------------------------------
Ronnie Brunner ronnie.brunner@netcetera.ch
Netcetera AG, 8040 Zuerich phone +41 1 247 79 79 fax +41 1 247 70 75
| |
| horape@gmail.com 2005-10-28, 7:58 am |
| Ronnie Brunner ha escrito:
> horape@gmail.com wrote:
> if (Tcl_SetVar2Ex(interpreter, "ARGV", NULL, ARGV,
Thanks! It works now.
HoraPe
|
|
|
|
|