/tags/ttn-post-libtool-1-4-3-upgrade/SWIG/Examples/php4/value/example.i

# · Swig · 31 lines · 20 code · 7 blank · 4 comment · 0 complexity · 7a6bb4959ce67ee98d29226552ace2c0 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. /* We use the Zend memory manager */
  15. Vector *v = (Vector *) emalloc(sizeof(Vector));
  16. v->x = x;
  17. v->y = y;
  18. v->z = z;
  19. return v;
  20. }
  21. void vector_print(Vector *v) {
  22. printf("Vector %x = (%g, %g, %g)\n", v, v->x, v->y, v->z);
  23. }
  24. %}