PageRenderTime 48ms CodeModel.GetById 23ms RepoModel.GetById 0ms 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. #include "example.h"
  5. %}
  6. /* Some functions that manipulate Vectors by value */
  7. extern double dot_product(Vector a, Vector b);
  8. extern Vector vector_add(Vector a, Vector b);
  9. /* Include this because the vector_add() function will leak memory */
  10. void free(void *);
  11. /* Some helper functions for our interface */
  12. %inline %{
  13. Vector *new_Vector(double x, double y, double z) {
  14. Vector *v = (Vector *) malloc(sizeof(Vector));
  15. v->x = x;
  16. v->y = y;
  17. v->z = z;
  18. return v;
  19. }
  20. void vector_print(Vector *v) {
  21. printf("Vector %x = (%g, %g, %g)\n", v, v->x, v->y, v->z);
  22. }
  23. %}