helloworld.c 652 Bytes
Newer Older
BO ZHANG's avatar
BO ZHANG committed
1
2
3
// Simple C program to display "Hello World"

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

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

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

Universebenzene's avatar
Universebenzene committed
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// 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);
}