I am faced with a small problem.
I have a c++ program, which sources a tcl file at run-time.
I wish to define a global variable in the c++ program and see if I can
access it in the Tcl function call without having to explicitly define
it as a result.
i.e.
proc myfunc {} {
global myvar # defined in C++ code
set myvar 0.0
}
On returning the variable myvar in C++ contains the value that is set.
Can some one please explain how to do this ?
Thanks
Sathya
For 'int' and 'double' variables, check
http://www.tcl.tk/man/tcl8.4/TclLib/LinkVar.htm
R'
Thanks. This is very useful.
Are there any extensions for regular array and named-array objects as
well ?
Thanks
Regards
Sathya Krishnamurthy
None that I know of. The concept of C/C++ arrays and TCL arrays is
completely different.
However, setting a trace on a TCL-array which updates the C-array
accordingly should work if the TCL array key is integer.
I haven't checked whether
int array[10];
Tcl_Linkvar( &array[0], "array(0)")
Tcl_Linkvar( &array[1], "array(1)")
...
would work.
R'
You may want to have a look into "vector" from blt.
those can be accessed as commands or in array style on the tcl side
and provide a c api.
http://manpages.debian.net/cgi-bin/display_man.cgi?id=1ffccf1c8389489e8bf47aacffaabe5d&format=plain
uwe
Thanks for your recommendations. I will try out some of these and get
back to you.
Thanks again
Sathya