|
From: bch <bra...@gm...> - 2025-09-23 18:46:08
|
> On Sep 23, 2025, at 09:01, Donal Fellows <don...@ma...> wrote:
>
>
> Emiliano wrote:
> That said, even the current docs recommends, in case of images, to use namespaces. image(n) reads "It is important to note that the image command will silently overwrite any procedure that may currently be defined by the given name, so choose the name wisely. It is recommended to use a separate namespace for image names (e.g., ::img::logo, ::img::large)."
>
> I remember writing that. It was based on the experience of doing [image create photo open ...] to make the icon for a button used to open files, and then wondering why my program broke! The important thing is avoiding overwriting existing commands.
>
> The actual workaround I originally used (in Tk 4.0, so a good while ago) was using default-named images and storing their handles in an array indexed by the names I really wanted.
What I do in my command-generating-code is test ( if(NULL!=Tcl_GetCommandFromObj(interp, objv[objc-1]){…; return TCL_ERROR}) - if overwriting is warranted, a “-force bool” switch can be used, but otherwise, it seems dangerous/disrespectful to blindly nuke another command. Or test the objProc and only nuke the packages own types…
% bch_pkg mk -foo 8 -bar mars puts ;# “puts” == name to be generated
Is a typical test in my development that has better fail.
-bch
>
> Donal.
> _______________________________________________
> Tcl-Core mailing list
> Tcl...@li...
> https://lists.sourceforge.net/lists/listinfo/tcl-core
|