Skip to content
helloworld.c 652 B
Newer Older
BO ZHANG's avatar
BO ZHANG committed
// Simple C program to display "Hello World"

// Header file for input output functions
Universebenzene's avatar
Universebenzene committed
#include <Python.h>
BO ZHANG's avatar
BO ZHANG committed

Universebenzene's avatar
Universebenzene committed
static PyObject* _helloworld(PyObject* self, PyObject* args)
BO ZHANG's avatar
BO ZHANG committed
{
Universebenzene's avatar
Universebenzene committed
    printf("Hello World\n");
    return Py_None;
}
BO ZHANG's avatar
BO ZHANG committed

Universebenzene's avatar
Universebenzene committed
static PyMethodDef Methods[] = {
    { "helloworld", _helloworld, METH_NOARGS, "Prints Hello World" },
    { NULL, NULL, 0, NULL }
};
BO ZHANG's avatar
BO ZHANG committed

Universebenzene's avatar
Universebenzene committed
// Our Module Definition struct
static struct PyModuleDef Module = {
    PyModuleDef_HEAD_INIT,
    "helloworld",
    "prints Hello World",
    -1,
    Methods
};

// Initializes our module using our above struct
PyMODINIT_FUNC PyInit_helloworld(void)
{
    return PyModule_Create(&Module);
}