作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
<分区>
我目前正在学习如何使用 Tcl-C api,我正在阅读“Tcl 和 Tk 中的实用编程 - 第四版”,但是当我有一个 C++ 程序时,我发现很难理解 API 的实际工作方式我想使用此 API 执行包装函数,这将为我提供一个将由我的脚本加载的共享对象。
我会尽量说得更清楚。
假设我有以下 C++ 文件:
/* example.h */
Class A {
private:
std::vector<int> data;
public:
A(){}
}
和 C 包装器文件:
/* match.c */
#include <tcl.h>
#include "example.h"
// should create an instance of an A object for future use.
int Tcl_ACmd (clientData, interp, argc, argv)
// should take an instance of an A object that was created and return it's data vector.
int Tcl_AGetDataCmd(clientData, interp, argc, argv)
int Match_Init(Tcl_Interp *interp)
{
if (NULL == Tcl_InitStubs (interp, TCL_VERSION, 0)) {
return TCL_ERROR;
}
Tcl_CreateCommand (interp, "A", Tcl_MaxCmd, (ClientData)NULL,(void (*)())NULL);
Tcl_CreateCommand (interp, "get", Tcl_MaxCmd, (ClientData)client_data,(void (*)())NULL);
return Tcl_PkgProvide(interp, "Match", "1.0");
}
最后是脚本:
# script.tcl
$> load match.o
$> A (This will create an A instance)
$> A get (this will return the data of A)
现在,我明白了,当我调用 AGetData 命令时,ClientData 实际上是 void* 类型,应该转换为 A 类。
但我仍然不太明白如何将参数传递给包装函数(我应该用 Tcl_Obj 更改 argv 吗?)以及对象的创建位置以及如何跟踪它们以便稍后通过脚本调用那里的方法。
我是一名优秀的程序员,十分优秀!