找回密码
 注册

QQ登录

只需一步,快速开始

BCM 门户 IT世界 应用开发 查看内容

Combining C and tcl/tk

2011-8-17 17:16| 发布者: admin| 查看: 653| 评论: 1|原作者: Test

摘要: Programming for X can be cumbersome, in comparison tcl/tk provides a quickand easy way of getting a graphical application up and running. Tcl/tk isa scripting language, and as such there are some thi ...
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.
  1. set say_hello_to "World"
复制代码

The following code is a the call in C to access the tcl/tk variable "say_hello_to".
  1.     char sHelloTo[30];

  2.     // after this call sHelloTo should contain "World"
  3.     strncpy( sHelloTo, Tcl_GetVar( pInterp, "say_hello_to", 0 ), 29 );
复制代码

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".
  1. Tcl_SetVar( pInterp, "say_hello_to", "World", 0 );
复制代码
12

鲜花

握手

雷人

路过

鸡蛋
发表评论

最新评论

引用 Test 2011-8-17 15:15
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.
  1. set say_hello_to "World"
复制代码

The following code is a the call in C to access the tcl/tk variable "say_hello_to".
  1.     char sHelloTo[30];

  2.     // after this call sHelloTo should contain "World"
  3.     strncpy( sHelloTo, Tcl_GetVar( pInterp, "say_hello_to", 0 ), 29 );

复制代码

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".
  1. Tcl_SetVar( pInterp, "say_hello_to", "World", 0 );
复制代码


查看全部评论(1)

手机版|小黑屋|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

返回顶部