I am working on Tcl. and using swig to extend the TCL command with C. Now, I want the extended command in C to callback the tcl procedure. But I have no idea of it.
Please help me.
First, I implement a dispatcher function in swig,which call mrecv. And in my tcl script. I call the mrecv to receive message. so, when a message arrived, i hope tcl can be notified by mrecv. that why I need find a way that invoke the callback tcl procedure from c.
And my codes is breifly is
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*/
}
and in my tcl script. I call mrecv command. tcl script:
res [ mrecv 3000 ]
I need to know how to notify tcl.
below is my test demo.
int testCallback (char * str) {
Tcl_Interp *interp;
interp=Tcl_CreateInterp();
Tcl_Eval(interp,str);
return 0;
}
testCallback() is the extended cmd which will be called by tcl. str is the procedure name in tcl.