[C++-sig] Re: instantiating python objects within C++
Ralf W. Grosse-Kunstleve
rwgk at yahoo.com
Wed May 28 08:32:31 CEST 2003
--- 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().
I am sure the exact details are more involved and my view is maybe not 100%
accurate, but the mental model works for me.
Ralf
__________________________________
Do you Yahoo!?
Yahoo! Calendar - Free online calendar with sync to Outlook(TM).
http://calendar.yahoo.com
More information about the Cplusplus-sig
mailing list