1 /*
2   Copyright 2016 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     return PyLong_FromLong(result);
31 }
32 
33 static PyMethodDef TachyonMethods[] = {
34     {"phaserize",  phaserize, METH_VARARGS,
35      "Shoot tachyon cannons."},
36     {NULL, NULL, 0, NULL}
37 };
38 
39 static struct PyModuleDef tachyonmodule = {
40    PyModuleDef_HEAD_INIT,
41    "tachyon",
42    NULL,
43    -1,
44    TachyonMethods
45 };
46 
PyInit_tachyon(void)47 PyMODINIT_FUNC PyInit_tachyon(void) {
48     return PyModule_Create(&tachyonmodule);
49 }
50