PageRenderTime 19ms CodeModel.GetById 18ms app.highlight 0ms RepoModel.GetById 1ms app.codeStats 0ms

/tags/rel-1-3-24/SWIG/Examples/tcl/value/example.i

#
Swig | 30 lines | 20 code | 7 blank | 3 comment | 0 complexity | 2b7d3d3a04918e6b4fbf06eaf4687d3e MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
 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 */
 9extern double dot_product(Vector a, Vector b);
10extern Vector vector_add(Vector a, Vector b);
11
12/* Include this because the vector_add() function will leak memory */
13void   free(void *);
14
15/* Some helper functions for our interface */
16%inline %{
17
18Vector *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
26void vector_print(Vector *v) {
27  printf("Vector %x = (%g, %g, %g)\n", v, v->x, v->y, v->z);
28}
29%}
30