| Accessing Variables Being able to call a C function by invoking a tcl/tk procedure allows youto have tcl/tk get help from C. In order to have C get help from tcl/tk there are a series of functions, the ones covered here will deal with getting information from, and putting information into a tcl/tk variable. Tcl_GetVar The "Tcl_GetVar" function returns a pointer to a string which contains the contents of the specified tcl/tk variable. The function takes three arguments,a pointer to the interpreter, a string with the name of the tcl/tk variable,and a flag. The variable that is accessed is at the current scope in theexecuting script associated with the interpreter. If there is no variable atthe current scope level with the given name then global variables are checked.If no matching global variable is found an error is returned. The flags argument allows you to specify TCL_GLOBAL_ONLY, in order to force the functionto only check for global variables with the given name. The following codeis part of a tcl/tk script that will be accessed.
The following code is a the call in C to access the tcl/tk variable "say_hello_to".
Tcl_SetVar The "Tcl_SetVar" function allows the programmer to change the contents ofa tcl/tk variable. The function takes four arguments, the first is a pointerto the interpreter, the second a string indicating the name of the tcl/tkvariable to change, the third is a string with the new value for the variable, and the last argument is for flags. The "Tcl_SetVar" flags are thesame as for "Tcl_GetVar". The "Tcl_SetVar" function returns NULL if an erroroccurred during the setting. If the variable does not exist, this functionwill create the variable locally to the scope currently in execution in thescript referenced by the interpreter pointer. The following code sets a tcl/tk variable called "say_hello_to" to contain the value "World".
|
手机版|小黑屋|BC Morning Website ( Best Deal Inc. 001 )
GMT-8, 2026-5-28 01:43 , Processed in 0.017807 second(s), 22 queries .
Supported by Weloment Group X3.5
© 2008-2026 Best Deal Online