-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexmodmodule.c
More file actions
64 lines (43 loc) · 1.25 KB
/
exmodmodule.c
File metadata and controls
64 lines (43 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <Python.h>
static PyObject *exmodError;
static PyObject* exmod_say_hello(PyObject* self, PyObject *args){
const char* msg;
int sts=0;
if(!PyArg_ParseTuple(args,"s",&msg)){
return NULL;
}
return NULL;
}
static PyObject* exmod_add(PyObject* self, PyObject *args){
double a,b;
double sts = 0;
if(!PyArg_ParseTuple(args,"dd",&a,&b)){
return NULL;
}
sts = a + b;
return Py_BuildValue("d", sts);
}
static PyObject* exmod_attr(PyObject* self, PyObject *args){
double strength,production;
double attr = 0;
if(!PyArg_ParseTuple(args,"dd",&strength,&production)){
return NULL;
}
attr = (255.-strength)/255. + production/30.;
return Py_BuildValue("d", attr);
}
static PyMethodDef exmod_methods[] = {
//PythonName, C-function name, argument presentation, description
{"say_hello", exmod_say_hello, METH_VARARGS, "Say Hello"},
{"add", exmod_add, METH_VARARGS, "Add two numbers in C"},
{"attr", exmod_attr, METH_VARARGS, "Computes attractiveness"},
{NULL, NULL, 0, NULL} /* Sentinel */
};
PyMODINIT_FUNC initexmod(void){
PyObject *m;
m = Py_InitModule("exmod", exmod_methods);
if( m == NULL) return;
exmodError = PyErr_NewException("exmod.error", NULL, NULL);
Py_INCREF(exmodError);
PyModule_AddObject(m, "error", exmodError);
}