1 %module pykludge3d
2 %{
3 #include <glib.h>
4 #include "geo.h"
5 #include "vertex.h"
6 #include "tools.h"
7 #include "pywrapper.h"
8 %}
9 
10 %typemap(python,in) GSList * {
11 
12 	/* Check if is a list */
13 	if(PyList_Check($source)) {
14 		int size = PyList_Size($source);
15 		int i = 0;
16 		$target = NULL;
17 		for(i = 0; i < size; i++) {
18 			PyObject *o = PyList_GetItem($source,i);
19 			if( PyString_Check(o) ) {
20 				void *ptr = NULL;
21 				if( SWIG_GetPtr( PyString_AsString(PyList_GetItem($source,i)), &ptr, NULL ) == NULL ) {
22 					$target = g_slist_append( $target, ptr );
23 				} else {
24 					PyErr_SetString(PyExc_TypeError,"list must contain pointers encoded as strings");
25 					g_slist_free((GSList *) $target);
26 					return NULL;
27 				}
28 			} else {
29 				PyErr_SetString(PyExc_TypeError,"list must contain strings");
30 				g_slist_free((GSList *) $target);
31 				return NULL;
32 			}
33 		}
34 	} else {
35 		PyErr_SetString(PyExc_TypeError,"not a list");
36 		return NULL;
37 	}
38 }
39 
40 %typemap(python,freearg) GSList * {
41 	g_slist_free((GSList *) $source);
42 }
43 
44 %typemap(python,out) GSList * {
45 	GSList *l;
46 	int i;
47 	$target = PyList_New( g_slist_length( $source ) );
48 	for( l = $source, i = 0; l; l = l->next ) {
49 		char buf[256];
50 		char * type;
51 		switch( ((Primitive*)l->data)->type ) {
52 			case PRIM_TYPE_VERTEX:
53 				type = "_Vertex_p";
54 				break;
55 			case PRIM_TYPE_POLY:
56 				type = "_Poly_p";
57 				break;
58 			default:
59 				type = "";
60 				break;
61 		}
62 		SWIG_MakePtr( buf, l->data, type );
63 		PyList_SetItem( $target, i++, PyString_FromString( buf ) );
64 	}
65 	g_slist_free( $source );
66 }
67 
68 
69 %typemap(python,in) float out[3] {
70   static float outresult[3];
71   $target = &outresult[0];
72 }
73 
74 %typemap(python,argout) float out[3] {
75 	int i;
76 	PyObject *o;
77 
78 	o = PyTuple_New(3);
79 	for (i = 0; i < 3; i++) {
80 		PyTuple_SetItem(o,i,PyFloat_FromDouble((double)($source[i])));
81 	}
82 	if (!$target) {
83 		$target = o;
84 	} else if ($target == Py_None) {
85 		Py_DECREF(Py_None);
86 		$target = o;
87 	} else {
88 		if (!PyList_Check($target)) {
89 			PyObject *o2 = $target;
90 			$target = PyList_New(0);
91 			PyList_Append($target,o2);
92 			Py_XDECREF(o2);
93 		}
94 		PyList_Append($target,o);
95 		Py_XDECREF(o);
96 	}
97 }
98 
99 %include pywrapper.h
100