/tags/rel-1.3.39/Examples/xml/example_inl.i

# · Swig · 30 lines · 20 code · 7 blank · 3 comment · 0 complexity · 9620de66d47f1db012ddd07efc62c5f9 MD5 · raw file

  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 %p = (%g, %g, %g)\n", v, v->x, v->y, v->z);
  22. }
  23. %}