Getting and Passing python class instance to C

Started by
2 comments, last by ManixReaper 13 years, 5 months ago
Hey,
I've been looking for a solution to my problem for a while but I can't seen to find anybody that may be trying to do exactly what I am (probably not a good thing)

I've embedded Python in my C program and am using boost.python for most of the binding.

I have a class which is totally in Python. It is passed to the C side of the program which is fine, I get a PyObject pointer which I can inspect and see that it knows it is of 'instance' type. The issue I am having now is I want to pass this instance, via a pure virtual function call back to python so other classes can access it.

Something like this:

void Update(float deltaTime, PyObject* gameObjects){	call_method<void>(self, "update", deltaTime, *gameObjects); }


However, when I try this I get the error:

Quote:TypeError: No to_python (by-value) converter found for C++ type: struct _object


Does anybody know what is going on? I really don't want to manipulate the python instance in C, all I want to do is just pass it along.

Thanks in advance
Advertisement
Why are you dereferencing gameObjects in your call_method() call?
This was the only way I could get this code to compile. I was assuming that dereferencing it wouldn't make a copy however since all of python's code is set up using ref counting.
Alright, I managed to figure out what I was doing wrong, kind of.

I’m using Boost.Python and I was trying to pass a python class instance from python to C and then back to python using a PyObject.

Boost.Python wraps PyObjects in its own boost::python::object class. By changing where I was using PyObjects* to boost::python::object everything works

Good to get it working but really wish I could have figured out how to do this using PyObjects

void Update(float deltaTime, boost::python::object gameObjects){    call_method<void>(self, "update", deltaTime, gameObjects); }	

This topic is closed to new replies.

Advertisement