第一个TCL自定义命令测试通过
2015-12-19 10:39
295 查看
首次按一定要安装好环境,下载tcl8.5就可以,直接。./configure&&make&&make install 即可。
一、test.c
#include <tcl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int
PowObjCmd(ClientData clientData, Tcl_Interp *interp,
int objc, Tcl_Obj *CONST objv[])
{
Tcl_Obj *resultptr;
double x,y,result;
int error;
if (objc != 3) {
Tcl_WrongNumArgs(interp,2,objv,
"Usage : pow x y");
return TCL_ERROR;
}
error = Tcl_GetDoubleFromObj(interp, objv[1], &x);
if (error != TCL_OK) return error;
error = Tcl_GetDoubleFromObj(interp, objv[2], &y);
if (error != TCL_OK) return error;
result = pow(x,y);
resultptr = Tcl_GetObjResult(interp);
Tcl_SetDoubleObj(resultptr,result);
return TCL_OK;
}
int
Example_Init(Tcl_Interp *interp) {
Tcl_CreateObjCommand(interp, "pow", PowObjCmd,
(ClientData) NULL, (Tcl_CmdDeleteProc *) NULL);
return TCL_OK;
}
二、makefile
#include <tcl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int
PowObjCmd(ClientData clientData, Tcl_Interp *interp,
int objc, Tcl_Obj *CONST objv[])
{
Tcl_Obj *resultptr;
double x,y,result;
int error;
if (objc != 3) {
Tcl_WrongNumArgs(interp,2,objv,
"Usage : pow x y");
return TCL_ERROR;
}
error = Tcl_GetDoubleFromObj(interp, objv[1], &x);
if (error != TCL_OK) return error;
error = Tcl_GetDoubleFromObj(interp, objv[2], &y);
if (error != TCL_OK) return error;
result = pow(x,y);
resultptr = Tcl_GetObjResult(interp);
Tcl_SetDoubleObj(resultptr,result);
return TCL_OK;
}
int
Example_Init(Tcl_Interp *interp) {
Tcl_CreateObjCommand(interp, "pow", PowObjCmd,
(ClientData) NULL, (Tcl_CmdDeleteProc *) NULL);
return TCL_OK;
}
三、test.tcl
#!/usr/bin/tclsh
load ./libtest.so example
pow 2 4
一、test.c
#include <tcl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int
PowObjCmd(ClientData clientData, Tcl_Interp *interp,
int objc, Tcl_Obj *CONST objv[])
{
Tcl_Obj *resultptr;
double x,y,result;
int error;
if (objc != 3) {
Tcl_WrongNumArgs(interp,2,objv,
"Usage : pow x y");
return TCL_ERROR;
}
error = Tcl_GetDoubleFromObj(interp, objv[1], &x);
if (error != TCL_OK) return error;
error = Tcl_GetDoubleFromObj(interp, objv[2], &y);
if (error != TCL_OK) return error;
result = pow(x,y);
resultptr = Tcl_GetObjResult(interp);
Tcl_SetDoubleObj(resultptr,result);
return TCL_OK;
}
int
Example_Init(Tcl_Interp *interp) {
Tcl_CreateObjCommand(interp, "pow", PowObjCmd,
(ClientData) NULL, (Tcl_CmdDeleteProc *) NULL);
return TCL_OK;
}
二、makefile
#include <tcl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int
PowObjCmd(ClientData clientData, Tcl_Interp *interp,
int objc, Tcl_Obj *CONST objv[])
{
Tcl_Obj *resultptr;
double x,y,result;
int error;
if (objc != 3) {
Tcl_WrongNumArgs(interp,2,objv,
"Usage : pow x y");
return TCL_ERROR;
}
error = Tcl_GetDoubleFromObj(interp, objv[1], &x);
if (error != TCL_OK) return error;
error = Tcl_GetDoubleFromObj(interp, objv[2], &y);
if (error != TCL_OK) return error;
result = pow(x,y);
resultptr = Tcl_GetObjResult(interp);
Tcl_SetDoubleObj(resultptr,result);
return TCL_OK;
}
int
Example_Init(Tcl_Interp *interp) {
Tcl_CreateObjCommand(interp, "pow", PowObjCmd,
(ClientData) NULL, (Tcl_CmdDeleteProc *) NULL);
return TCL_OK;
}
三、test.tcl
#!/usr/bin/tclsh
load ./libtest.so example
pow 2 4
相关文章推荐
- hibernate 中无法成功创建表
- Grub2登录绕过验证漏洞
- opencv cvCreateVideoWriter()参数
- PHP memcached使用
- 《数据挖掘导论》学习
- 时域分析与频域分析
- 让IE6 IE7 IE8 IE9 IE10 IE11支持Bootstrap的解决方法
- Sqlite常用表查询语句
- FireEye 666漏洞
- http方法的在web的实现
- FPGrowth算法理论
- nginx性能优化技巧
- maven的学习之路——intellij的maven1.5JDK问题
- leetcode第1题——**Two Sum
- c#-关于自动属性的思考
- 微信企业号应用回调模式开启
- qt中的lineEdit文本输入框的输入类型限制(三种验证类)
- 二叉树的创建和前中后三种遍历方法
- 分布算法之一致性哈希算法
- Joomla远程代码执行漏洞分析