Created
February 19, 2024 04:28
-
-
Save itamaro/3e677b3d70deb7dde840ac3344795fe4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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