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

David Abrahams dave at boost-consulting.com
Mon May 26 18:23:37 CEST 2003


Gavin Doughtie <gdoughtie at anim.dreamworks.com> writes:

> I just did this last week. You DO have to run the interpreter...

No, ya don't.

> ...which
> then loads a python script, which imports your exported C++ class that
> you've written (or generated) a wrapper class for that has the
> call_method implementations of your virtual functions. When you
> extract to a pointer of your base class, you've really got a pointer
> to the wrapper class which calls back into the python code.

Wow! That's really complicated!

See the last example at
http://www.boost.org/libs/python/doc/tutorial/doc/derived_object_types.html

    object FooClass
        = class_<Foo>("Foo", init<int, char const*>())
               .def( ... )
               ...
               ;

    object foo = FooClass(3, "hello");

Joel, we might want to do that example in two steps as shown above
just to make it crystal clear what's happening.

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





More information about the Cplusplus-sig mailing list