[C++-sig] How to create package structure in single extension module (original) (raw)

David Abrahams dave at boost-consulting.com
Tue Dec 13 18:03:15 CET 2005


"Koen Van Herck" <koen_van_herck at yahoo.com> writes:

Hello,

I would like to do something similar as the example in http://www.boost.org/libs/python/doc/tutorial/doc/html/python/techniques.htm l#python.creatingpackages:

import sounds import sounds.io import sounds.filters sound = sounds.io.open('file.mp3') newsound = sounds.filters.echo(sound, 1.0) but, contrary to the example, by providing only a single sounds.pyd module. The reason is that I'm wrapping a library that uses multiple namespaces and I would like to expose these namespaces to Python. It's not possible though to split the library into different compiled entities. How can I do this using Boost.Python ?

Use the Python 'C' API to create module objects for io and filters, and then stick them in the scope of your sounds module as follows:

scope().attr("io") = io;
scope().attr("filters") = filters;

And then you can go on to wrap things in those modules via:

scope io_scope = io;

class_<sounds::io::whatever>("whatever")
   ...
   ;

HTH,

Dave Abrahams Boost Consulting www.boost-consulting.com



More information about the Cplusplus-sig mailing list