I defined a tcl command in c++
Tcl_CreateObjCommand(interp, "myproc", myproc_func, nullptr, nullptr);
in tclsh
% rename myproc newproc
in C code
myproc_func(ClientData clientData,Tcl_Interp *interp,int objc,Tcl_Obj *const objv[])
at this moment when I run
% newproc
It will call myproc's function, which is myproc_func, but at this time myproc_func's objv[0]->bytes corresponds to the name "newproc", which causes me to fail in looking for the function corresponding to the function name named newproc.
Is it possible to map commands after rename to commands before in tcl?
In Tcl, once you use the rename command to change the name of a procedure or command, you cannot directly remap the new name back to the original name of the command. The rename command effectively changes the name of the command in the interpreter's namespace, and it doesn't create a new mapping from the new name to the old name.
In your scenario, you initially registered a command named "myproc" with C++ code, and then you used rename to change it to "newproc." After this renaming, you cannot directly map "newproc" back to "myproc" within Tcl.
However, you can work around this by creating a wrapper procedure or alias that calls the renamed command. Here's how you can do it:
In the code above, we define a myproc_wrapper procedure that takes any number of arguments (args) and then uses uplevel to execute the renamed command "newproc" with those arguments. You can add any pre-processing or post-processing as needed within the wrapper.
This way, you can effectively achieve the behavior of calling the original "myproc" even though it was renamed to "newproc."
Let me know if this helps.