summaryrefslogtreecommitdiff
path: root/Examples/php/simple
diff options
context:
space:
mode:
authorLorry Tar Creator <lorry-tar-importer@baserock.org>2009-08-18 20:56:02 +0000
committerLorry <lorry@roadtrain.codethink.co.uk>2012-09-25 16:59:08 +0000
commit9f8a09ed743cedd9547bf0661d518647966ab114 (patch)
tree9c7803d3b27a8ec22e91792ac7f7932efa128b20 /Examples/php/simple
downloadswig-tarball-master.tar.gz
Imported from /srv/lorry/lorry-area/swig-tarball/swig-1.3.40.tar.gz.HEADswig-1.3.40master
Diffstat (limited to 'Examples/php/simple')
-rw-r--r--Examples/php/simple/Makefile24
-rw-r--r--Examples/php/simple/example.c23
-rw-r--r--Examples/php/simple/example.i10
-rwxr-xr-xExamples/php/simple/runme.php25
4 files changed, 82 insertions, 0 deletions
diff --git a/Examples/php/simple/Makefile b/Examples/php/simple/Makefile
new file mode 100644
index 0000000..0862ce5
--- /dev/null
+++ b/Examples/php/simple/Makefile
@@ -0,0 +1,24 @@
+TOP = ../..
+SWIG = $(TOP)/../preinst-swig
+SRCS = example.c
+TARGET = example
+INTERFACE = example.i
+LIBS =
+SWIGOPT =
+
+all::
+ $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
+ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \
+ php
+
+static::
+ $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
+ SWIGOPT='$(SWIGOPT)' TARGET='myphp' INTERFACE='$(INTERFACE)' \
+ php_static
+
+clean::
+ $(MAKE) -f $(TOP)/Makefile php_clean
+ rm -f $(TARGET).php
+
+check: all
+ $(MAKE) -f $(TOP)/Makefile php_run
diff --git a/Examples/php/simple/example.c b/Examples/php/simple/example.c
new file mode 100644
index 0000000..2fe2756
--- /dev/null
+++ b/Examples/php/simple/example.c
@@ -0,0 +1,23 @@
+/* File : example.c */
+#include <stdio.h>
+
+/* A global variable */
+double Foo = 3.0;
+
+void print_Foo() {
+ printf("In C, Foo = %f\n",Foo);
+}
+
+/* Compute the greatest common divisor of positive integers */
+int gcd(int x, int y) {
+ int g;
+ g = y;
+ while (x > 0) {
+ g = x;
+ x = y % x;
+ y = g;
+ }
+ return g;
+}
+
+
diff --git a/Examples/php/simple/example.i b/Examples/php/simple/example.i
new file mode 100644
index 0000000..af4ff08
--- /dev/null
+++ b/Examples/php/simple/example.i
@@ -0,0 +1,10 @@
+/* File : example.i */
+%module example
+
+%{
+ extern double Foo;
+%}
+
+extern double Foo;
+void print_Foo();
+int gcd(int x, int y);
diff --git a/Examples/php/simple/runme.php b/Examples/php/simple/runme.php
new file mode 100755
index 0000000..0e96fe8
--- /dev/null
+++ b/Examples/php/simple/runme.php
@@ -0,0 +1,25 @@
+<?php
+
+require "example.php";
+
+# Call our gcd() function
+
+$x = "42 aaa";
+$y = 105;
+$g = gcd($x,$y);
+print "The gcd of $x and $y is $g\n";
+
+# Manipulate the Foo global variable
+
+# Output its current value
+print "Foo = " . Foo_get() . "\n";
+
+# Change its value
+Foo_set(3.1415926);
+
+# See if the change took effect ( this isn't a good example for php, see
+# manual for why. )
+print "Foo = " . Foo_get() . "\n";
+print_Foo();
+
+?>