Boost logo

Boost-Build :

From: David Abrahams (dave_at_[hidden])
Date: 2004-07-06 04:47:20


The following message is a courtesy copy of an article
that has been posted to gmane.comp.lib.boost.user as well.

mayankg_at_[hidden] writes:

Please bring Boost.Python questions to the C++-sig:
http://www.boost.org/more/mailing_lists/cplussig

> Hi,
> I have the following type of functions in a class say "MyClass", which I have
> exported to python.
>
> 1) func1(long *plong)
> 2) func2(TempClass **pptempclass) (where TempClass is some other class)
>
> Now, I exported these using the following:
>
> .def("func1", &MyClass::func1)
> .def("func2", &MyClass::func2)
>
> and it compiled well.
>
> But now when I try to use them in a python script, I have no clue as to how I
> create and pass:
> 1) a long pointer as argument to func1
> 2) a double pointer to TempClass as argument to func2
>
> How do I achieve this behaviour?

You don't. Python ints and floats are immutable, so you can't pass
them to a C++ function that could change them.

> 1) Do I have to wrap the above functions> If yes, then how? How will they be
> used in python then?

The latter is the question I would ask you: how would you like/expect
to be able to use them from Python? You have to come up with an
appropriate interface (e.g. "in Python func1 accepts and returns an
int"); once you've done that, it's usually easy to wrap the function.

-- 
Dave Abrahams
Boost Consulting
http://www.boost-consulting.com
 

Boost-Build list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk