Can we rename constructors like we rename functions using the %rename directive?
%rename(create_cell) Cell(string);
Basically, I want to end up with something like create_cell
instead of new_Cell
.
I suspect that you can't at that point (did you try it to see if it works?) but there are a few things you can do. (Only do one of them, of course.)
"new_Cell"
is "create_cell"
. I think you should be able to find the place to change in an argument a function call like Tcl_CreateCommand or Tcl_CreateObjCommand
, but might also be in a macro depending on how the code generation is done. (I've never actually looked.)Use load
to get the code into Tcl and then rename
the command afterwards. Names are not fixed in stone. The load
might be inside the implementation of a call to package require
; just do what you would normally do to get the code working with the wrong name first, and then do this:
rename new_Cell create_cell
Add a wrapper command or procedure; any of these will do:
proc create_cell args {
eval new_Cell $args
}
# With 8.5 or later
proc create_cell args {
new_Cell {*}$args
}
# With 8.6
proc create_cell args {
tailcall new_Cell {*}$args
}
# Or do this; not a procedure, an alias
interp alias {} create_cell {} new_Cell
rename
to move the wrappednew_Cell
to another Tcl namespace where it won't interfere so much with what you're seeing. Purely cosmetic, but convenient. (Myself, I'd wrap everything because I don't really like the interface style that SWIG produces; Tcl isn't C++ and its APIs have their own flavor. - Donal Fellows 2012-04-04 07:07