summaryrefslogtreecommitdiffstats
path: root/bindings
diff options
context:
space:
mode:
Diffstat (limited to 'bindings')
-rw-r--r--bindings/lang_python.py20
-rw-r--r--bindings/lang_python_wrapper_bottom.c17
-rw-r--r--bindings/lang_python_wrapper_top.c66
3 files changed, 103 insertions, 0 deletions
diff --git a/bindings/lang_python.py b/bindings/lang_python.py
index 9a49ee65..7a9cb316 100644
--- a/bindings/lang_python.py
+++ b/bindings/lang_python.py
@@ -30,7 +30,10 @@ class PythonBinding:
self.generate_header(fd)
for clss in self.binding_data.structs:
self.generate_class(clss, fd)
+ fd.close()
+ fd = open('python/_lasso.c', 'w')
+ self.generate_wrapper(fd)
fd.close()
def generate_header(self, fd):
@@ -149,5 +152,22 @@ _lasso.init()
print >> fd, ''
+ def generate_wrapper(self, fd):
+ print >> fd, open('lang_python_wrapper_top.c').read()
+ for m in self.binding_data.functions:
+ self.generate_function_wrapper(m, fd)
+ for c in self.binding_data.structs:
+ for m in c.methods:
+ self.generate_function_wrapper(m, fd)
+ print >> fd, open('lang_python_wrapper_bottom.c').read()
+
+ def generate_function_wrapper(self, m, fd):
+ name = m.name[6:]
+ print >> fd, '''static PyObject*
+%s(PyObject *self, PyObject *args)
+{''' % name
+
+ print >> fd, '''}
+'''
diff --git a/bindings/lang_python_wrapper_bottom.c b/bindings/lang_python_wrapper_bottom.c
new file mode 100644
index 00000000..737ec02e
--- /dev/null
+++ b/bindings/lang_python_wrapper_bottom.c
@@ -0,0 +1,17 @@
+PyMODINIT_FUNC
+init_lasso(void)
+{
+ if (PyType_Ready(&PyGObjectPtrType) < 0)
+ return;
+
+ m = Py_InitModule3("_lasso", lasso_methods, "_lasso wrapper module");
+ lasso_init();
+
+ lasso_wrapper_key = g_quark_from_static_string("PyLasso::wrapper");
+
+ Py_INCREF(&PyGObjectPtrType);
+ PyModule_AddObject(m, "PyGobjectPtr", (PyObject *)&PyGobjectPtrType);
+
+
+}
+
diff --git a/bindings/lang_python_wrapper_top.c b/bindings/lang_python_wrapper_top.c
new file mode 100644
index 00000000..6c5f74a2
--- /dev/null
+++ b/bindings/lang_python_wrapper_top.c
@@ -0,0 +1,66 @@
+#include <Python.h>
+#include <lasso/lasso.h>
+
+GQuark lasso_wrapper_key;
+
+
+typedef struct {
+ PyObject_HEAD
+ GObject *obj;
+} PyGObjectPtr;
+
+static PyTypeObject PyGObjectPtrType;
+
+static void
+PyGObjectPtr_dealloc(PyGObjectPtr *self)
+{
+ g_object_unref(self->obj);
+ self->ob_type->tp_free((PyObject*)self);
+}
+
+static PyObject*
+PyGObjectPtr_New(GObject *obj)
+{
+ PyGObjectPtr *self;
+
+ if (obj == NULL) {
+ Py_INCREF(Py_None);
+ return Py_None;
+ }
+
+ self = (PyGObjectPtr*)g_object_get_qdata(obj, lasso_wrapper_key)
+ if (self != NULL) {
+ Py_INCREF(self);
+ } else {
+ self = (PyGObjectPtr*)PyObject_NEW(PyGObjectPtr, &PyGObjectPtrType);
+ g_object_set_qdata_full(obj, lasso_wrapper_key, self, NULL);
+ self->obj = obj;
+ }
+ return (PyObject*)self;
+}
+
+static PyTypeObject PyGObjectPtrType = {
+ PyObject_HEAD_INIT(NULL),
+ 0, /* ob_size */
+ "_lasso.PyGObjectPtr", /* tp_name */
+ sizeof(PyGObjectPtr), /* tp_basicsize */
+ 0, /* tp_itemsize */
+ (destructor)PyGObjectPtr_dealloc, /* tp_dealloc */
+ 0, /*tp_print*/
+ 0, /*tp_getattr*/
+ 0, /*tp_setattr*/
+ 0, /*tp_compare*/
+ 0, /*tp_repr*/
+ 0, /*tp_as_number*/
+ 0, /*tp_as_sequence*/
+ 0, /*tp_as_mapping*/
+ 0, /*tp_hash */
+ 0, /*tp_call*/
+ 0, /*tp_str*/
+ 0, /*tp_getattro*/
+ 0, /*tp_setattro*/
+ 0, /*tp_as_buffer*/
+ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
+ "PyGObjectPtr objects", /* tp_doc */
+};
+