1

Having C++ code:

namespace ns {
    struct Person {};
}

I would like to expose Person class to python in a module ns:

import libapp
x = libapp.ns.Person()

Is it possible using swig?

I other workds I would like to map C++ namespace hierarchy to Python module hierarchy.

I have a wrapper written in Boost.Python (it allows such mapping) and I'm switching to swig, so I do not want to rewrite wrapper client code.

nicolai
  • 1,140
  • 9
  • 17

1 Answers1

0

The easiest answer to this is to write one SWIG module per namespace that you want to expose, so in the instance above you'd write a SWIG module called ns inside your libapp package.

You can reference the other namespaces still within other modules using the SWIG %import directive.

You could also do some juggling with either the runtime information SWIG produces to hook this up at runtime, or even at compile time, but the complexity of doing so far outweighs the benefits of splitting your module up cleanly anyway.

Flexo
  • 87,323
  • 22
  • 191
  • 272