import source from 1.3.40
[external/swig.git] / Examples / xml / example_inl.i
1 // Tests SWIG's handling of pass-by-value for complex datatypes
2 %module example
3
4 %{
5 #include "example.h"
6 %}
7
8 /* Some functions that manipulate Vectors by value */
9 extern double dot_product(Vector a, Vector b);
10 extern Vector vector_add(Vector a, Vector b);
11
12 /* Include this because the vector_add() function will leak memory */
13 void   free(void *);
14
15 /* Some helper functions for our interface */
16 %inline %{
17
18 Vector *new_Vector(double x, double y, double z) {
19    Vector *v = (Vector *) malloc(sizeof(Vector));
20    v->x = x;
21    v->y = y;
22    v->z = z;
23    return v;
24 }
25
26 void vector_print(Vector *v) {
27   printf("Vector %p = (%g, %g, %g)\n", v, v->x, v->y, v->z);
28 }
29 %}
30