Calling a python function from C++

L

lamthierry

Let's say I have a python function do some math like the following:

def doMath(self):
self.val = self.val + 1


How can I call this python function from C++? Assuming I have some sort
of Python wrapper around my C++ codes.
 
?

=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=

Let's say I have a python function do some math like the following:

def doMath(self):
self.val = self.val + 1


How can I call this python function from C++? Assuming I have some sort
of Python wrapper around my C++ codes.

See the "Embedding and Extending" tutorial. In short, you write

resultObj = PyObject_CallMethod(selfObj, "doMath", "");
if (resultObj == NULL)
return NULL;
Py_DECREF(resultObj); // resultObj should be Py_None

How you get hold of self depends on your application.

Regards,
Martin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
474,238
Messages
2,571,193
Members
47,830
Latest member
ZacharySap

Latest Threads

Top