aboutsummaryrefslogtreecommitdiff
path: root/Examples/ocaml/argout_ref
diff options
context:
space:
mode:
authorArt Yerkes <ayerkes@speakeasy.net>2003-03-21 16:26:52 +0000
committerArt Yerkes <ayerkes@speakeasy.net>2003-03-21 16:26:52 +0000
commit6418b0c755b12bc1ecafa006c36273ef94ac914f (patch)
tree3baa174bd1be82e37af2c3c268452a45d29b2108 /Examples/ocaml/argout_ref
parent7d2accbca7c3ccbd9c612e7b97866572d089b4cc (diff)
downloadswig-6418b0c755b12bc1ecafa006c36273ef94ac914f.tar.gz
Added example.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@4603 626c5289-ae23-0410-ae9c-e8d60b6d4f22
Diffstat (limited to 'Examples/ocaml/argout_ref')
-rw-r--r--Examples/ocaml/argout_ref/Makefile27
-rw-r--r--Examples/ocaml/argout_ref/example.c19
-rw-r--r--Examples/ocaml/argout_ref/example.i4
-rw-r--r--Examples/ocaml/argout_ref/example_prog.ml16
4 files changed, 66 insertions, 0 deletions
diff --git a/Examples/ocaml/argout_ref/Makefile b/Examples/ocaml/argout_ref/Makefile
new file mode 100644
index 000000000..bb48801e7
--- /dev/null
+++ b/Examples/ocaml/argout_ref/Makefile
@@ -0,0 +1,27 @@
+TOP = ../..
+SWIG = $(TOP)/../swig
+SRCS = example.c
+TARGET = example
+INTERFACE = example.i
+MLFILE = example.ml
+PROGFILE = example_prog.ml
+OBJS = example.o
+
+all:: static
+
+static::
+ $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
+ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' MLFILE='$(MLFILE)' \
+ PROGFILE='$(PROGFILE)' OBJS='$(OBJS)' \
+ ocaml_static_cpp
+
+dynamic::
+ $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
+ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' MLFILE='$(MLFILE)' \
+ PROGFILE='$(PROGFILE)' OBJS='$(OBJS)' \
+ ocaml_dynamic_cpp
+
+clean::
+ $(MAKE) -f $(TOP)/Makefile MLFILE='$(MLFILE)' ocaml_clean
+
+check: all
diff --git a/Examples/ocaml/argout_ref/example.c b/Examples/ocaml/argout_ref/example.c
new file mode 100644
index 000000000..6f095cddb
--- /dev/null
+++ b/Examples/ocaml/argout_ref/example.c
@@ -0,0 +1,19 @@
+/* File : example.c */
+
+/* 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;
+}
+
+extern "C" void factor( int &x, int &y ) {
+ int gcd_xy = gcd( x,y );
+ x /= gcd_xy;
+ y /= gcd_xy;
+}
diff --git a/Examples/ocaml/argout_ref/example.i b/Examples/ocaml/argout_ref/example.i
new file mode 100644
index 000000000..a0be05f24
--- /dev/null
+++ b/Examples/ocaml/argout_ref/example.i
@@ -0,0 +1,4 @@
+/* File : example.i */
+%module example
+
+extern "C" void factor(int &x, int &y);
diff --git a/Examples/ocaml/argout_ref/example_prog.ml b/Examples/ocaml/argout_ref/example_prog.ml
new file mode 100644
index 000000000..bcf23251e
--- /dev/null
+++ b/Examples/ocaml/argout_ref/example_prog.ml
@@ -0,0 +1,16 @@
+(* example_prog.ml *)
+
+open Example
+
+exception BadReturn
+
+let x = int_of_string Sys.argv.(1)
+let y = int_of_string Sys.argv.(2)
+let (xf,yf) = match _factor (C_list [ C_int x ; C_int y ]) with
+ C_list [ C_int a ; C_int b ] -> a,b
+ | _ -> raise BadReturn
+let _ = print_endline
+ ("Factorization of " ^ (string_of_int x) ^
+ " and " ^ (string_of_int y) ^
+ " is " ^ (string_of_int xf) ^
+ " and " ^ (string_of_int yf))