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 :)