PageRenderTime 45ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/trunk/Examples/perl5/value/example.i

#
Swig | 32 lines | 22 code | 7 blank | 3 comment | 0 complexity | 140e005847e87329ecc4fa03d091a3d3 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. %inline %{
  8. extern double dot_product(Vector a, Vector b);
  9. extern Vector vector_add(Vector a, Vector b);
  10. %}
  11. /* Include this because the vector_add() function will leak memory */
  12. void free(void *);
  13. /* Some helper functions for our interface */
  14. %inline %{
  15. Vector *new_Vector(double x, double y, double z) {
  16. Vector *v = (Vector *) malloc(sizeof(Vector));
  17. v->x = x;
  18. v->y = y;
  19. v->z = z;
  20. return v;
  21. }
  22. void vector_print(Vector *v) {
  23. printf("Vector %p = (%g, %g, %g)\n", v, v->x, v->y, v->z);
  24. }
  25. %}