0

I've followed this video tutorial on setting up a very basic C++ extension for python using Visual Studio. It's very straightforward and works quite nicely. https://www.youtube.com/watch?v=y_eh00oE5rI

Here's what my code looks like.

#ifdef _DEBUG
#define _DEBUG_WAS_DEFINED
#undef _DEBUG
#endif

#include <Python.h>

#define MODULE_NAME "DummyExt"

PyObject* greet(PyObject* self, PyObject* args)
{
    return PyString_FromString("Hello world!");
}

PyMethodDef DummyExtMethods[] = 
{
    {"greet", greet, METH_NOARGS, nullptr}
};

PyMODINIT_FUNC
initDummyExt(void)
{
    PyObject* m;
    m = Py_InitModule(MODULE_NAME, DummyExtMethods);
    if (m == nullptr)
    {
        return;
    }
}


#ifdef _DEBUG_WAS_DEFINED
#define _DEBUG 1
#endif

How can I use python's APIs to expose C++ classes from an extension? I want to be able to define my class and its logic in C++ and be able to instantiate it from python and call its member functions and whatnot. As the title says I don't want to use any 3rd party tools and such, only the headers and libs that come with python.

Any help would be appreciated :)

DNg
  • 422
  • 2
  • 15
  • Please disregard this question. After reading up more on python's APIs, without a 3rd party tool, this will be far too gargantuan of an undertaking and I've given up on going this route. – DNg Nov 02 '16 at 11:17
  • You can delete the question – DavidW Nov 20 '16 at 12:59

0 Answers0