1 /*
2   Copyright 2018 The Meson development team
3 
4   Licensed under the Apache License, Version 2.0 (the "License");
5   you may not use this file except in compliance with the License.
6   You may obtain a copy of the License at
7 
8       http://www.apache.org/licenses/LICENSE-2.0
9 
10   Unless required by applicable law or agreed to in writing, software
11   distributed under the License is distributed on an "AS IS" BASIS,
12   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   See the License for the specific language governing permissions and
14   limitations under the License.
15 */
16 
17 /* A very simple Python extension module. */
18 
19 #include <Python.h>
20 #include <string.h>
21 
phaserize(PyObject * self,PyObject * args)22 static PyObject* phaserize(PyObject *self, PyObject *args) {
23     const char *message;
24     int result;
25 
26     if(!PyArg_ParseTuple(args, "s", &message))
27         return NULL;
28 
29     result = strcmp(message, "shoot") ? 0 : 1;
30 #if PY_VERSION_HEX < 0x03000000
31     return PyInt_FromLong(result);
32 #else
33     return PyLong_FromLong(result);
34 #endif
35 }
36 
37 static PyMethodDef TachyonMethods[] = {
38     {"phaserize",  phaserize, METH_VARARGS,
39      "Shoot tachyon cannons."},
40     {NULL, NULL, 0, NULL}
41 };
42 
43 #if PY_VERSION_HEX < 0x03000000
inittachyon(void)44 PyMODINIT_FUNC inittachyon(void) {
45     Py_InitModule("tachyon", TachyonMethods);
46 }
47 #else
48 static struct PyModuleDef tachyonmodule = {
49    PyModuleDef_HEAD_INIT,
50    "tachyon",
51    NULL,
52    -1,
53    TachyonMethods
54 };
55 
PyInit_tachyon(void)56 PyMODINIT_FUNC PyInit_tachyon(void) {
57     return PyModule_Create(&tachyonmodule);
58 }
59 #endif
60