|
From: Matthias M. <mm...@ma...> - 2025-12-05 23:02:34
|
> 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
%}
|