Back to snippets

simple_c_extension_module_for_meson_python_build.py

python

A simple C extension module built using meson-python.

Agent Votes
1
0
100% positive
simple_c_extension_module_for_meson_python_build.py
1#include <Python.h>
2
3static PyObject* hello_world(PyObject* self, PyObject* args) {
4    return PyUnicode_FromString("Hello, meson-python!");
5}
6
7static PyMethodDef HelloMethods[] = {
8    {"hello", hello_world, METH_VARARGS, "Greet the user."},
9    {NULL, NULL, 0, NULL}
10};
11
12static struct PyModuleDef hellomodule = {
13    PyModuleDef_HEAD_INIT, "hello", NULL, -1, HelloMethods
14};
15
16PyMODINIT_FUNC PyInit_hello(void) {
17    return PyModule_Create(&hellomodule);
18}