[C++-sig] Exposing base classes in different Boost.Python modules

Hans Meine meine at informatik.uni-hamburg.de
Thu Jul 26 12:46:23 CEST 2007


Am Mittwoch, 25. Juli 2007 22:37:52 schrieb Lawrence Spector:
> Fine, this makes sense.  However, if I'm going to expose this, I want to
> make a different module called std, so it's in the right namespace.  Is
> there a way to tell Boost.Python to automatically import this one before my
> other module, so it knows what to do with std::wostream or another way to
> make this work?

Yes.  Have a look at the new boost::python::import() function - I use it to 
import dependency modules, too.  Or, if you are using an older boost version:

BOOST_PYTHON_MODULE_INIT(bar)
{
    // import foo to make sure that basic converters  are available for
    // default arguments:
    {
        PyObject *fooMod = PyImport_ImportModule("foo");
        Py_XDECREF(fooMod);
    }
    ...
}

Ciao, /  /
     /--/
    /  / ANS



More information about the Cplusplus-sig mailing list