]> khamidou — GitHub mirrors - te.git/commitdiff
writing the python binding
authorkhamidou <karim@lambda-expr.org>
Fri, 17 Jul 2009 17:40:09 +0000 (19:40 +0200)
committerkhamidou <karim@lambda-expr.org>
Fri, 17 Jul 2009 17:40:09 +0000 (19:40 +0200)
interp.c
interp.h

index 6c5e0b5fdffc89d81a238b441e32b5a868349d19..a264342d40f11a2e0a69f491fcac4beb8962e79e 100644 (file)
--- 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);
 }
+
index 595e837ea87ff0f94c861caf70022cf292cfef8a..f795fd6c117c936c42b5de2c5a698b6ae51d2c77 100644 (file)
--- a/interp.h
+++ b/interp.h
@@ -9,8 +9,24 @@ conventions : the declarations using mixed case always refer to elements of the
 #include <Python.h>
 #include <structmember.h>
 #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);