[C++-sig] Re: python and C++?

David Abrahams david.abrahams at rcn.com
Sun May 5 23:30:39 CEST 2002


"Totte Karlsson" <mtk at u.washington.edu> wrote in message
news:ab42mt$2ati$1 at nntp6.u.washington.edu...
> Thanks I'll test boost,
> How about SWIG? is boost preferable? any opinions?

SWIG's approach is very different. Being the designer of Boost.Python, I'll
let others comment on what's preferable. My sense is that SWIG has very
different strengths.

> I read that you can't wrap C++ functions which return pointers? sounds
like
> a big limitation to me. My classes return pointers all the time.. is there
a
> workaround?
> I want to use the simplest and most versatile..

Boost.Python v2 supports pointer return types, but that's still in a
pre-release phase, mostly due to missing documentation. Several people are
using it successfully to wrap major C++ projects. I can help you get started
with that, if you like.

To look at Boost.Python v2, get the current boost CVS state and examine

$(BOOST_ROOT)/libs/python/doc/v2

Examples are available in the following files located at

$(BOOST_ROOT)/libs/python/test

newtest.py m1.cpp m2.cpp
test_builtin_converters.py test_builtin_converters.cpp
test_pointer_adoption.[py/cpp]
callbacks.[py/cpp]
virtual_functions.[py/cpp]
bpl-test back_reference.[py/cpp]
bpl-test implicit.[py/cpp]
bpl-test data_members.[py/cpp]

In Boost.Python v2, the object referenced by a returned pointer is copied by
default, but you can instead create a Python object which holds a reference
to any of the wrapped function's arguments to keep the pointee alive.

-Dave

> /totte
>
> "David Abrahams" <david.abrahams at rcn.com> wrote in message
> news:ab3mgb$mgc$1 at bob.news.rcn.net...
> >
> > "Totte Karlsson" <mtk at u.washington.edu> wrote in message
> > news:ab1r85$1u8s$1 at nntp6.u.washington.edu...
> > > Hi,
> > > Is there any good texts about how to interface to a windows dll with
> > python?
> > > I'm a total beginner of python.
> > > I'm a C++ programmer and what I want is to make a DLL and interface to
> > that
> > > one with python.
> > > Say for example, I have a C++ class, called mtkMatrix. Is it then
> possible
> > > to allocate a mtkMatrix in a python script and acess its class member
> > > functions?
> > > thanks
> > > /totte
> >
> > Boost.Python was specifically designed to address your needs
> > (www.boost.org/libs/python/doc/). If you need help getting started,
please
> > direct further questions to the C++-sig:
> > http://www.python.org/sigs/c++-sig/.
> >
> > HTH,
> > Dave
> >
> > P.S. I strongly recommend using the latest boost CVS state
> > (http://sourceforge.net/cvs/?group_id=7586) rather than the current
> release
> > version.
> >
> >
>
>








More information about the Cplusplus-sig mailing list