[C++-sig] Re: instantiating python objects within C++

David Abrahams dave at boost-consulting.com
Wed May 28 12:47:22 CEST 2003


"Ralf W. Grosse-Kunstleve" <rwgk at yahoo.com> writes:

> --- Stefan Seefeld <seefeld at sympatico.ca> wrote:
>> David Abrahams wrote:
>> 
>> > The Boost.Python shared library has a converter registry where all of
>> > this information is stored.
>> 
>> ok, this seems really to be the key. How does this work ? I'm a bit confused,
>> as conceptually the lines
>> 
>> BOOST_PYTHON_MODULE(Sandbox)
>> {
>>    python::class_<Base> base_type("Base");
>>    //...
>> }
>> 
>> create a type 'Sandbox.Base', i.e. the equivalent in C++ would be
>> something like 'Sandbox::Base'. However, 'Sandbox' isn't a type,
>> so I wonder how I can access the above type object from inside
>> C++.
>
> I cannot conclusively answer all your questions, but maybe I can help with one
> piece of the puzzle: the central Boost.Python type conversion registry is *not*
> scoped. It knows about your type only as, e.g., namespace1::namespace2::base.
> If I understand correctly the class_<> constructor does two more or less
> independent things (at runtime):
>
> 1. It registers the type conversions in the central registry with the C++ type
> (in some form) as the key.
>
> 2. It adds a reference to the Python type (created at compile time!) to the
> current scope().

The Python type is created at runtime, ...

> I am sure the exact details are more involved and my view is maybe not 100%
> accurate, but the mental model works for me.

...but your mental model is basically correct.

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com





More information about the Cplusplus-sig mailing list