import source from 1.3.40
[external/swig.git] / Examples / perl5 / value / example.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 %inline %{
10 extern double dot_product(Vector a, Vector b);
11 extern Vector vector_add(Vector a, Vector b);
12 %}
13
14 /* Include this because the vector_add() function will leak memory */
15 void   free(void *);
16
17 /* Some helper functions for our interface */
18 %inline %{
19
20 Vector *new_Vector(double x, double y, double z) {
21    Vector *v = (Vector *) malloc(sizeof(Vector));
22    v->x = x;
23    v->y = y;
24    v->z = z;
25    return v;
26 }
27
28 void vector_print(Vector *v) {
29   printf("Vector %p = (%g, %g, %g)\n", v, v->x, v->y, v->z);
30 }
31 %}
32