Skip to content

Instantly share code, notes, and snippets.

@itamaro
Created February 19, 2024 04:28
Show Gist options
  • Save itamaro/3e677b3d70deb7dde840ac3344795fe4 to your computer and use it in GitHub Desktop.
Save itamaro/3e677b3d70deb7dde840ac3344795fe4 to your computer and use it in GitHub Desktop.
#include "Python.h"
PyObject* get_message(PyObject* self, PyObject* args) {
PyObject* message = PyUnicode_FromString("hello from extension");
return message;
}
static PyMethodDef hello_methods[] = {
{"get_message",
get_message,
METH_NOARGS,
"Get a generic hello message"},
{NULL, NULL, 0, NULL}};
static PyModuleDef hello_module = {
PyModuleDef_HEAD_INIT,
"hello",
.m_size = -1,
.m_methods = hello_methods,
.m_free = NULL,
};
PyMODINIT_FUNC PyInit_hello_ext_123() {
PyObject* module = PyModule_Create(&hello_module);
return module;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment