From b1336101f89b19e781dafc60f0f9e5f48e154e39 Mon Sep 17 00:00:00 2001 From: khamidou Date: Fri, 17 Jul 2009 19:40:09 +0200 Subject: [PATCH] writing the python binding --- interp.c | 34 +++++++++++++++++++++++++++++++++- interp.h | 25 ++++++++++++++++++------- 2 files changed, 51 insertions(+), 8 deletions(-) diff --git a/interp.c b/interp.c index 6c5e0b5..a264342 100644 --- a/interp.c +++ b/interp.c @@ -15,7 +15,38 @@ PyMODINIT_FUNC init_python(void) Py_INCREF(&binding_BufferType); PyModule_AddObject(m, "Buffer", (PyObject *)&binding_BufferType); - + PySys_SetPath("."); + pName = PyString_FromString("te_test"); + + pModule = PyImport_Import(pName); + + if (pModule == NULL) { + perror("Unable to open te_test.py !"); + PyErr_Print(); + getc(stdin); + exit(EXIT_FAILURE); + } + + Py_DECREF(pName); +} + +void terminate_python(void) +{ + Py_DECREF(pFunc); + Py_DECREF(pModule); + +} +PyObject *Te_notifyprintf(PyObject *self, PyObject *args) +{ + const char *str; + int sts; + + if (!PyArg_ParseTuple(args, "s", &str)) + return NULL; + + miniprintf("%s", str); + return Py_BuildValue("i", 0); /* miniprintf is always successful */ + } PyObject *Buffer_new(PyTypeObject *type, PyObject *args, PyObject *kwds) @@ -148,3 +179,4 @@ int Buffer_setcontents(TeBuffer *self, PyObject *value, void *closure) self->buf->point = (int) PyInt_AsLong(value); } + diff --git a/interp.h b/interp.h index 595e837..f795fd6 100644 --- a/interp.h +++ b/interp.h @@ -9,8 +9,24 @@ conventions : the declarations using mixed case always refer to elements of the #include #include #include "buffer.h" + +static PyObject *pName, *pModule, *pDict, *pFunc; void init_interp(void); + +PyObject *Te_notifyprintf(PyObject *self, PyObject *args); + +/* the methods of the te module */ +static PyMethodDef TeMethods[] = { +// {"system", spam_system, METH_VARARGS, +// "Execute a shell command."}, + {"notifyprintf", Te_notifyprintf, METH_VARARGS, "Print a message in the minibuffer"}, + {NULL, NULL, 0, NULL} /* Sentinel */ +}; + +/* + Definition of the buffer object type. + */ typedef struct { PyObject_HEAD @@ -29,7 +45,8 @@ int Buffer_setpoint(TeBuffer *self, PyObject *value, void *closure); PyObject *Buffer_getcontents(TeBuffer *self, void *closure); int Buffer_setcontents(TeBuffer *self, PyObject *value, void *closure); - + + static PyMemberDef Buffer_members[] = { {NULL} /* Sentinel */ }; @@ -100,12 +117,6 @@ static PyTypeObject binding_BufferType = { }; -/* the methods of the te module */ -static PyMethodDef TeMethods[] = { -// {"system", spam_system, METH_VARARGS, -// "Execute a shell command."}, - {NULL, NULL, 0, NULL} /* Sentinel */ -}; PyMODINIT_FUNC init_python(void); -- 2.43.0