
passing arguments C++ => Tcl
Quote:
> Question ... : I have a problem with passing multiple arguments between
> a function written in C and the code in Tcl/Tk.
> In C++, I have :
> Tcl_CreateCommand(interp, "get_info", Tcl_Load_Info, NULL, NULL);
> int Tcl_Load_Info(ClientData clientdata, Tcl_Interp* interp, int argc,
> char* argv[])
> {
> ...............................
> int a = 5;
> int b = 10;
> int c = 15;
> ...................................
> return TCL_OK;
> }
> -----------------------------------------------------------------------------------------
> In Tcl, I have :
> ---------------------------------------------------
> proc test {} {
> "get_info"
> .......
> # rest of the program, using values a, b, c -> obtained from C-function
> }
> ---------------------------------------------------
Let get_info have three parameters, namely the variable names.
Then you can set the variables from within C (or C++ in your case).
Have a look at Tcl_SetVar and Tcl_SetVar2. which set the variables
in the *current* context:
proc test {} \
{
get_info a b c
puts $a
puts $b
puts $c
}
If you want to use the variables outside test, the best way is
IMHO to handle this at the script level:
proc test {} \
{
global a ;#makes it global
upvar B b ;makes it visible in the caller of test
#nothing ;#c stays local :-)
get_info a b c
}
Greetings!
Volker
--
Das meiste Geld habe ich fuer exklusive Restaurants, schnelle Autos und
teure Frauen ausgegeben. Den Rest habe ich verplempert.