forked from jvan/pyvrui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
typemaps.i
74 lines (64 loc) · 1.93 KB
/
typemaps.i
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
65
66
67
68
69
70
71
72
73
// Convert python list to Vrui::Application constructor args
// python input type: list
// expected c++ type: (int&, char**&)
%typemap(in) (int& argc, char**& argv) {
/* Check if input is a list */
if (PyList_Check($input)) {
int i;
int num_args = (int)PyList_Size($input);
char** args = (char**)malloc((num_args+1)*sizeof(char*));
for (i=0; i<num_args; i++) {
PyObject* o = PyList_GetItem($input, i);
if (PyString_Check(o)) {
args[i] = PyString_AsString(PyList_GetItem($input, i));
} else {
PyErr_SetString(PyExc_TypeError, "list must contain strings");
free(args);
return NULL;
}
}
args[i] = 0;
$1 = &num_args;
$2 = &args;
/*free(args);*/
} else {
PyErr_SetString(PyExc_TypeError, "not a list");
return NULL;
}
}
// Convert python list to Geometry::Vector object
%typemap(in) const Geometry::Vector<double, 3>& {
PyObject* x = PyList_GetItem($input, 0);
PyObject* y = PyList_GetItem($input, 1);
PyObject* z = PyList_GetItem($input, 2);
double px = PyFloat_AsDouble(x);
double py = PyFloat_AsDouble(y);
double pz = PyFloat_AsDouble(z);
$1 = new Geometry::Vector<double, 3>(px, py, pz);
}
%typemap(free) const Geometry::Vector<double, 3>& {
delete $1;
}
// Convert python list to Vrui::Point object
%typemap(in) const Vrui::Point& {
PyObject* x = PyList_GetItem($input, 0);
PyObject* y = PyList_GetItem($input, 1);
PyObject* z = PyList_GetItem($input, 2);
double px = PyFloat_AsDouble(x);
double py = PyFloat_AsDouble(y);
double pz = PyFloat_AsDouble(z);
$1 = new Vrui::Point(px, py, pz);
}
%typemap(free) const Vrui::Point& {
delete $1;
}
%typemap(in) GLfloat {
$1 = PyFloat_AsDouble($input);
}
%typemap(out) GLfloat {
$result = PyFloat_FromDouble($1);
}
%typemap(typecheck) GLfloat = float;
%typemap(in) GLsizei {
$1 = PyLong_AsLong($input);
}