C++ 如何使tcl解释器在退出命令后不继续? static int MyReplacementExit(客户端数据未使用、Tcl_Interp*Interp、int argc、const char*argv[]) { //Tcl_DeleteInterp(interp); //Tcl_Finalize(); 返回TCL_OK; } int main(){ Tcl_Interp*Interp=Tcl_CreateInterp(); Tcl_CreateCommand(interp,“exit”,MyReplacementExit,NULL,NULL); Tcl_Eval(interp,“退出;卖出11111”); std::cout
替换C++ 如何使tcl解释器在退出命令后不继续? static int MyReplacementExit(客户端数据未使用、Tcl_Interp*Interp、int argc、const char*argv[]) { //Tcl_DeleteInterp(interp); //Tcl_Finalize(); 返回TCL_OK; } int main(){ Tcl_Interp*Interp=Tcl_CreateInterp(); Tcl_CreateCommand(interp,“exit”,MyReplacementExit,NULL,NULL); Tcl_Eval(interp,“退出;卖出11111”); std::cout,c++,tcl,exit,C++,Tcl,Exit,替换exit删除解释器(这会停止执行更多命令,但实际上不会立即删除仍在使用的数据结构)重要的是,将对Tcl\u Eval的调用包装为对Tcl\u Preserve和Tcl\u Release的调用。如果可以避免的话,不要调用Tcl\u Finalize;这是在您即将从内存中卸载Tcl库时使用的,而且可能会非常棘手(坦白说,退出这个过程比较容易) 以下是如何使用您的代码(改编): 是的,这意味着您希望将设置解释器所需的工作量保持在相当小的范围内;您可能不希望尝试在中断时每毫秒调用一次此函数……您是
exit
删除解释器(这会停止执行更多命令,但实际上不会立即删除仍在使用的数据结构)重要的是,将对Tcl\u Eval
的调用包装为对Tcl\u Preserve
和Tcl\u Release
的调用。如果可以避免的话,不要调用Tcl\u Finalize
;这是在您即将从内存中卸载Tcl库时使用的,而且可能会非常棘手(坦白说,退出这个过程比较容易)
以下是如何使用您的代码(改编):
是的,这意味着您希望将设置解释器所需的工作量保持在相当小的范围内;您可能不希望尝试在中断时每毫秒调用一次此函数……您是否尝试从您的
出口调用替换项?@JohannesKuhn这可能是一个解决方案,但我的tcl版本是8.4,它不支持tcl\u CancelEv在MyReplacementExit中返回TCL_BREAK或TCL_CONTINUE如何?它会跳过重新定义的“exit”之后的命令执行吗?$VictorBurenkov在从进程调用exit时将不起作用。需要作为原始exit命令工作
static int
MyReplacementExit(ClientData unused, Tcl_Interp *interp, int argc, const char *argv[])
{
// Tcl_DeleteInterp(interp);
// Tcl_Finalize();
return TCL_OK;
}
int main() {
Tcl_Interp *interp = Tcl_CreateInterp();
Tcl_CreateCommand(interp, "exit", MyReplacementExit, NULL, NULL);
Tcl_Eval(interp, "exit ; puts 11111111");
std::cout << "22222222222" << std::endl;
return 0;
}
static int
MyReplacementExit(ClientData unused, Tcl_Interp *interp, int argc, const char *argv[])
{
Tcl_DeleteInterp(interp); // <------------------
return TCL_OK;
}
int main() {
Tcl_Interp *interp = Tcl_CreateInterp();
Tcl_CreateCommand(interp, "exit", MyReplacementExit, NULL, NULL);
Tcl_Preserve(interp); // <------------------
Tcl_Eval(interp, "exit ; puts 11111111");
Tcl_Release(interp); // <------------------
std::cout << "22222222222" << std::endl;
return 0;
}
Tcl_Preserve(interp);
if (Tcl_Eval(interp, theScriptToEval) != TCL_OK)
// Handle unexpected errors here
if (!Tcl_InterpDeleted(interp))
Tcl_DeleteInterp(interp);
Tcl_Release(interp);