I defined a tcl command in c++
Tcl_CreateObjCommand(interp, "myproc", myproc_func, nullptr, nullptr);
in tclsh
% rename myproc ""
Does this completely remove myproc? If I define another myproc command, is it possible to associate it with the myproc defined in c++?
When you delete a command (using
rename myproc ""), you lose all references to it. There is no way to get the command back, short of recreating it from scratch.If you want to temporarily make myproc unavailable, you can rename to some special name, then rename it back to reinstate it:
Of course, the intermediate code can still call __myproc.
Another approach is to hide the command:
This still doesn't completely prevent access to the function, as it can be invoked using:
interp invokehidden {} myproc.It all depends on why you want to do this. Are you afraid that some code uses myproc when it shouldn't? Or do you want to recover from code that may delete the function? In that case, you may want to run the untrusted code in a (safe) slave interpreter.