SWIG directors and nested classes

279 views
Skip to first unread message

Ivar Gaitan

unread,
Sep 15, 2014, 10:22:30 AM9/15/14
to golan...@googlegroups.com
Is the Go SWIG module supposed to generate directors for nested classes?

I only seem to get the outer class director generated, even with the promiscuous version of the directive:

// generate directors for all classes that have virtual methods
%feature("director");

class Outer {
public:
 
class Inner {
 
public:
   
virtual void methodA() = 0;
 
};

 
virtual void methodB() = 0;
};

So, Is this feature not implemented in the Go module, or am I doing it wrong, or is it a bug?

(The only remotely related issue I found on Github was this one, but it was fixed 6 months ago.)

/Ivar

Ian Lance Taylor

unread,
Sep 15, 2014, 1:43:18 PM9/15/14
to Ivar Gaitan, golang-nuts
On Mon, Sep 15, 2014 at 7:22 AM, Ivar Gaitan <ivar....@gmail.com> wrote:
>
> Is the Go SWIG module supposed to generate directors for nested classes?
>
> I only seem to get the outer class director generated, even with the
> promiscuous version of the directive:
>
> // generate directors for all classes that have virtual methods
>
> %feature("director");
>
> class Outer {
> public:
> class Inner {
> public:
> virtual void methodA() = 0;
> };
>
> virtual void methodB() = 0;
> };
>
> So, Is this feature not implemented in the Go module, or am I doing it
> wrong, or is it a bug?

Which version of SWIG are you using? SWIG had no real nested class
support at all before 3.0.

Go of course does not itself have nested classes. With SWIG 3.0 you
can get this kind of thing to work if you use

%feature("flatnested");

I don't know if there is a better way to handle this.

Ian

Ivar Gaitan

unread,
Sep 15, 2014, 3:56:58 PM9/15/14
to golan...@googlegroups.com, ivar....@gmail.com


Den måndagen den 15:e september 2014 kl. 19:43:18 UTC+2 skrev Ian Lance Taylor:

Which version of SWIG are you using?  SWIG had no real nested class
support at all before 3.0.

Go of course does not itself have nested classes.  With SWIG 3.0 you
can get this kind of thing to work if you use

%feature("flatnested");

I don't know if there is a better way to handle this.

Ian

Thanks, I will try that tomorrow. Reading through the docs (a bit sloppy perhaps) I got the impression that 'flatnested' was a Java/C# only feature, and that the flattening was implicit for Go. Btw, I'm on 3.0.2.

On a side note, I'm very impressed with how well Go and SWIG play together. Like the perhaps(?) unintentional way you can use #cgo directives to pass compiler/linker flags to gcc calls in the swig build chain. The only thing I miss from the go-swig build chain is a way to pass include paths to the swig command, which you may need for your %include directives.

Ivar

Ivar Gaitan

unread,
Sep 16, 2014, 8:18:39 AM9/16/14
to golan...@googlegroups.com, ivar....@gmail.com

Go of course does not itself have nested classes.  With SWIG 3.0 you
can get this kind of thing to work if you use

%feature("flatnested");


Yup, works like a charm. Thanks Ian!

Ivar 
Reply all
Reply to author
Forward
0 new messages