The great merge
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@4141 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
6fcc22a1f8
commit
516036631c
1508 changed files with 125983 additions and 44037 deletions
4
SWIG/Examples/php4/value/BUILD.sh
Executable file
4
SWIG/Examples/php4/value/BUILD.sh
Executable file
|
|
@ -0,0 +1,4 @@
|
|||
#! /bin/sh -e
|
||||
|
||||
${SWIG:=swig} -php4 -phpfull -noproxy -withc example.c example.i
|
||||
phpize && ./configure && make clean && make
|
||||
15
SWIG/Examples/php4/value/Makefile.old
Normal file
15
SWIG/Examples/php4/value/Makefile.old
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
TOP = ../..
|
||||
SWIG = $(TOP)/../swig
|
||||
SRCS = example.c
|
||||
TARGET = php_example
|
||||
INTERFACE = example.i
|
||||
SWIGOPT = -noproxy
|
||||
|
||||
all::
|
||||
$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
|
||||
SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' php4
|
||||
|
||||
clean::
|
||||
rm -f *_wrap* *.o core *~ *.so *.php php_example.h
|
||||
|
||||
check: all
|
||||
15
SWIG/Examples/php4/value/example.c
Normal file
15
SWIG/Examples/php4/value/example.c
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
/* File : example.c */
|
||||
|
||||
#include "example.h"
|
||||
|
||||
double dot_product(Vector a, Vector b) {
|
||||
return (a.x*b.x + a.y*b.y + a.z*b.z);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
5
SWIG/Examples/php4/value/example.h
Normal file
5
SWIG/Examples/php4/value/example.h
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
/* File : example.h */
|
||||
|
||||
typedef struct {
|
||||
double x, y, z;
|
||||
} Vector;
|
||||
31
SWIG/Examples/php4/value/example.i
Normal file
31
SWIG/Examples/php4/value/example.i
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
// Tests SWIG's handling of pass-by-value for complex datatypes
|
||||
%module example
|
||||
|
||||
%{
|
||||
#include "example.h"
|
||||
%}
|
||||
|
||||
/* Some functions that manipulate Vectors by value */
|
||||
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);
|
||||
}
|
||||
%}
|
||||
|
||||
35
SWIG/Examples/php4/value/runme.php4
Normal file
35
SWIG/Examples/php4/value/runme.php4
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
|
||||
require "example.php";
|
||||
|
||||
|
||||
$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";
|
||||
vector_print($v);
|
||||
vector_print($w);
|
||||
|
||||
echo "\nNow I'm going to compute the dot product\n";
|
||||
|
||||
$d = dot_product($v, $w);
|
||||
|
||||
echo "dot product = $d (should be 68)\n";
|
||||
|
||||
echo "\nNow I'm going to add the vectors together\n";
|
||||
|
||||
$r = vector_add($v, $w);
|
||||
|
||||
vector_print($r);
|
||||
|
||||
echo "The value should be (11,13,15)\n";
|
||||
|
||||
echo "\nNow I'm going to clean up the return result\n";
|
||||
|
||||
# free($r);
|
||||
|
||||
echo "Good\n";
|
||||
|
||||
?>
|
||||
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue