From: kruland <kr...@us...> - 2005-08-24 16:32:50
|
Update of /cvsroot/swig/SWIG/Examples/php4/value In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12012/value Modified Files: BUILD.sh example.c example.h example.i runme.php4 Log Message: Updated examples to function correctly with new php4 module. Added some supplemental examples for cpointer, overloading and references using proxies. Index: example.i =================================================================== RCS file: /cvsroot/swig/SWIG/Examples/php4/value/example.i,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** example.i 28 Jun 2005 21:11:07 -0000 1.3 --- example.i 24 Aug 2005 16:32:41 -0000 1.4 *************** *** 6,30 **** %} ! /* Some functions that manipulate Vectors by value */ ! %inline %{ ! extern double dot_product(Vector a, Vector b); ! extern Vector vector_add(Vector a, Vector b); ! %} ! ! /* Include this because the vector_add() function will leak memory */ ! void free(void *); /* Some helper functions for our interface */ %inline %{ - Vector *new_Vector(double x, double y, double z) { - /* We use the Zend memory manager */ - Vector *v = (Vector *) emalloc(sizeof(Vector)); - v->x = x; - v->y = y; - v->z = z; - return v; - } - void vector_print(Vector *v) { printf("Vector %x = (%g, %g, %g)\n", v, v->x, v->y, v->z); --- 6,14 ---- %} ! %include "example.h" /* Some helper functions for our interface */ %inline %{ void vector_print(Vector *v) { printf("Vector %x = (%g, %g, %g)\n", v, v->x, v->y, v->z); Index: example.h =================================================================== RCS file: /cvsroot/swig/SWIG/Examples/php4/value/example.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** example.h 30 Nov 2002 21:58:58 -0000 1.2 --- example.h 24 Aug 2005 16:32:41 -0000 1.3 *************** *** 4,5 **** --- 4,8 ---- double x, y, z; } Vector; + + double dot_product(Vector a, Vector b); + void vector_add(Vector a, Vector b, Vector* result); Index: example.c =================================================================== RCS file: /cvsroot/swig/SWIG/Examples/php4/value/example.c,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** example.c 30 Nov 2002 21:58:57 -0000 1.2 --- example.c 24 Aug 2005 16:32:41 -0000 1.3 *************** *** 7,15 **** } ! Vector vector_add(Vector a, Vector b) { ! Vector r; ! r.x = a.x + b.x; ! r.y = a.y + b.y; ! r.z = a.z + b.z; ! return r; } --- 7,13 ---- } ! void vector_add(Vector a, Vector b, Vector* result) { ! result->x = a.x + b.x; ! result->y = a.y + b.y; ! result->z = a.z + b.z; } Index: BUILD.sh =================================================================== RCS file: /cvsroot/swig/SWIG/Examples/php4/value/BUILD.sh,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** BUILD.sh 30 Nov 2002 21:58:57 -0000 1.2 --- BUILD.sh 24 Aug 2005 16:32:41 -0000 1.3 *************** *** 1,4 **** #! /bin/sh -e ! ${SWIG:=swig} -php4 -phpfull -noproxy -withc example.c example.i ! phpize && ./configure && make clean && make --- 1,5 ---- #! /bin/sh -e ! ${SWIG:=swig} -php4 -make -noproxy -withc example.c example.i ! make ! php -d extension_dir=. runme.php4 Index: runme.php4 =================================================================== RCS file: /cvsroot/swig/SWIG/Examples/php4/value/runme.php4,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** runme.php4 30 Nov 2002 21:58:58 -0000 1.2 --- runme.php4 24 Aug 2005 16:32:41 -0000 1.3 *************** *** 4,9 **** ! $v = new_vector(1.0,2.0,3.0); ! $w = new_vector(10.0,11.0,12.0); echo "I just created the following vector\n"; --- 4,16 ---- ! $v = new_vector(); ! vector_x_set($v,1.0); ! vector_y_set($v,2.0); ! vector_z_set($v,3.0); ! ! $w = new_vector(); ! vector_x_set($w,10.0); ! vector_y_set($w,11.0); ! vector_z_set($w,12.0); echo "I just created the following vector\n"; *************** *** 19,23 **** echo "\nNow I'm going to add the vectors together\n"; ! $r = vector_add($v, $w); vector_print($r); --- 26,31 ---- echo "\nNow I'm going to add the vectors together\n"; ! $r = new_vector(); ! vector_add($v, $w, $r); vector_print($r); |