[C++-sig] Passing Boost wrapped classes (refs and/or pointers) to/from Python and C++

Mike Dickheiser miked at sinistergames.com
Mon Jun 10 16:32:17 CEST 2002


Ok. I've wrapped numerous C++ class using Boost, and I know how to call
Python functions from C++ and vice versa. But how do I call these functions
using a reference or pointer to one of my wrapped classes?

For example, say I have wrapped the C++ class "Vector3" and have the
following Python script:

def DoSomething(args)
   x = Vector3()
   x.set(0.0, 0.0, 0.0)

   y = [a Vector3 passed into args]
   y.set(0.0, 0.0, 0.0)


So, how do I extract 'y' from 'args'?

And how would I do it if a Vector3* were passed into args instead?

For that matter, how do I pack a Vector3 or Vector3* into the args to begin
with on the C++ side?

Finally, if I had DoSomething() return a Vector3, how would the C++ code
that called the function convert the returned PyObject into a Vector3?

I've searched all the documentation I can find on boost and Python, and
haven't found any discussion on how this is done. I've seen references to
functions that look like they are related to the process (e.g. "to_python"),
but no help on when/where/why to use them. In any case, what I HAVE found is
in the straight Python help, so I'm wary about using it because I'm now
using Boost which I would expect to provide a different (read: far easier)
mechanism.

Thanks for any help
Mike Dickheiser






More information about the Cplusplus-sig mailing list