【发布时间】:2014-02-26 16:53:14
【问题描述】:
我正在研究 Tcl。并使用 swig 用 C 扩展 TCL 命令。 现在,我希望 C 中的扩展命令回调 tcl 过程。 但我不知道。
请帮帮我。
首先,我在 swig 中实现了一个调度程序函数,它调用 mrecv。 在我的 tcl 脚本中。我打电话给 mrecv 来接收消息。所以,当消息到达时,我希望 mrecv 可以通知 tcl。这就是为什么我需要找到一种从 c 调用回调 tcl 过程的方法。
我的代码很简单
W16 mrecv(int timeout) {
W16 res;
Msg_t *msg = NULL;
APP_EVENT_T eventList[255];
int listLength = 255;
while (1) {
readAgain = 0;
msg = malloc(sizeof(Msg_t));
if (!msg) {
return RETURN_ERR;
}
memset(msg, 0, sizeof(Msg_t));
res = MsgRecvEvent(msg, eventList, &listLength, timeout);
if (res == RETURN_OK) {
msgDispatcher(msg);
}
free(msg);
}
return res;
}
void msgDispather(void *msg) {
/*notify tcl*/
}
在我的 tcl 脚本中。我调用 mrecv 命令。 tcl 脚本:
res [ mrecv 3000 ]
我需要知道如何通知 tcl。
下面是我的测试演示。
int testCallback (char * str) {
Tcl_Interp *interp;
interp=Tcl_CreateInterp();
Tcl_Eval(interp,str);
return 0;
}
testCallback() 是 tcl 调用的扩展 cmd。 str 是 tcl 中的过程名称。
【问题讨论】:
-
你能把你的问题说得更具体一些吗?目前这对于 StackOverflow 来说有点太宽泛了。到目前为止,您尝试过什么,您在哪里卡住了?
-
你真的不想经常创建解释器(它们是重量级的)并且它们没有被垃圾收集。您可能还想使用现有的,以便用户可以在您必须实际处理回调之前进行设置……