|
From: <and...@bl...> - 2025-12-17 10:20:43
|
Hi Matthias
Thanks for your input. I have now managed to do an initial wrapping using the new FL namespace. I have tried to keep usage in pyFltk more or less the same as before, this means, I had to divide the whole thing into two components.
This of course caused several follow-up problems which I am addressing now one by one. All in all, it seems though that this is the correct approach and it does actually simplify certain things in the end.
By the way, just out of curiosity, is there a specific reason that only FL.H is using the new namespace and not everything? In my uses of namespaces so far, we have always tried to put things like libraries into one common namespace so as not to overly pollute the global namespace.
Best regards
Andreas
> Matthias Melcher <mm...@ma...> hat am 05.12.2025 23:37 CET geschrieben:
>
>
> > On 2. Dec 2025, at 20:53, Andreas Held <and...@bl...> wrote:
> >
> > Hi Matthias
> >
> > Thanks for pointing out the added namespaces. I actually created a branch of pyFltk for covering fltk1.5 some time ago, but it seems that the namespaces are quite a recent addition and I didn't have a look at t yet.
> >
> > Actually, we are not using pybind but swig to wrap fltk. At the moment, swig is still namespace unaware, that means, everything is merged into the global module namespace. It seems there might b a possibility by creating separate modules bu this is something I still need to get better acquainted with.
> >
> > If you have some good ideas how to best cover this then you are more than welcome.
> >
> > Best regards
> >
> > Andreas
>
> Hi Andreas,
>
> stupid question since I am not a master of SWIG by any means. I looked at the SWIG source code and the docs, and I think that %module and %rename may help us here. So I asked Copilot to write me some code.
>
> I can offer to mark function and variables in the header somehow, if that helps.
>
>
> Option 1:
>
>
> %module Fl
>
> // Rename the namespace members to remove the namespace prefix
> %rename("%(strip:[Fl::])s") "";
>
> // Include the header
> %{
> #include "FL/Fl.H"
> %}
>
> %include "FL/Fl.H"
>
> This will make Fl::run() available as Fl.run() in Python.
>
>
> Option 2:
>
>
> %module Fl
>
> %{
> #include "FL/Fl.H"
> using namespace Fl; // Bring namespace into global scope for wrapper
> %}
>
> // Tell SWIG to ignore the namespace and treat contents as global
> %ignore Fl;
> namespace Fl {
> %rename("%(strip:[Fl::])s") "";
> %include "FL/Fl.H"
> }
>
>
> Option 3: look extremely work intensive
>
>
> %module Fl
>
> %{
> #include "FL/Fl.H"
> %}
>
> // Manually expose each function/class from the namespace
> %inline %{
> void run() { Fl::run(); }
> // Add other Fl namespace members as needed
> %}
>
> _______________________________________________
> Pyfltk-user mailing list
> Pyf...@li...
> https://lists.sourceforge.net/lists/listinfo/pyfltk-user
|