diff options
| author | Lorry Tar Creator <lorry-tar-importer@baserock.org> | 2009-08-18 20:56:02 +0000 |
|---|---|---|
| committer | Lorry <lorry@roadtrain.codethink.co.uk> | 2012-09-25 16:59:08 +0000 |
| commit | 9f8a09ed743cedd9547bf0661d518647966ab114 (patch) | |
| tree | 9c7803d3b27a8ec22e91792ac7f7932efa128b20 /Examples/ocaml/stl | |
| download | swig-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/ocaml/stl')
| -rw-r--r-- | Examples/ocaml/stl/Makefile | 33 | ||||
| -rw-r--r-- | Examples/ocaml/stl/example.h | 17 | ||||
| -rw-r--r-- | Examples/ocaml/stl/example.i | 12 | ||||
| -rw-r--r-- | Examples/ocaml/stl/runme.ml | 13 |
4 files changed, 75 insertions, 0 deletions
diff --git a/Examples/ocaml/stl/Makefile b/Examples/ocaml/stl/Makefile new file mode 100644 index 0000000..fa4333e --- /dev/null +++ b/Examples/ocaml/stl/Makefile @@ -0,0 +1,33 @@ +TOP = ../.. +SWIG = $(TOP)/../preinst-swig +SRCS = +TARGET = example +INTERFACE = example.i +PROGFILE = runme.ml + +all default:: static + +static:: + $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + PROGFILE='$(PROGFILE)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \ + ocaml_static_cpp + +director:: + $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + PROGFILE='$(PROGFILE)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \ + ocaml_static_cpp_director + +dynamic:: + $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + PROGFILE='$(PROGFILE)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \ + ocaml_static_cpp + +toplevel:: + $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + PROGFILE='$(PROGFILE)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \ + ocaml_static_cpp_toplevel + +clean:: + $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' ocaml_clean + +check: all diff --git a/Examples/ocaml/stl/example.h b/Examples/ocaml/stl/example.h new file mode 100644 index 0000000..df5762b --- /dev/null +++ b/Examples/ocaml/stl/example.h @@ -0,0 +1,17 @@ +/* File : example.h -- stolen from the guile std_vector example */ + +#include <string> +#include <vector> +#include <algorithm> +#include <functional> +#include <numeric> + +using std::string; + +double vec_write(std::vector<string> v) { + int n = 0; + for( std::vector<string>::iterator i = v.begin(); + i != v.end(); + i++ ) + printf( "%04d: %s\n", ++n, i->c_str() ); +} diff --git a/Examples/ocaml/stl/example.i b/Examples/ocaml/stl/example.i new file mode 100644 index 0000000..19a80a6 --- /dev/null +++ b/Examples/ocaml/stl/example.i @@ -0,0 +1,12 @@ +%module example +%{ +#include "example.h" +%} + +#define ENABLE_CHARPTR_ARRAY +#define ENABLE_STRING_VECTOR +%include stl.i + +%feature("director"); + +%include example.h diff --git a/Examples/ocaml/stl/runme.ml b/Examples/ocaml/stl/runme.ml new file mode 100644 index 0000000..2fa5d20 --- /dev/null +++ b/Examples/ocaml/stl/runme.ml @@ -0,0 +1,13 @@ +(* This example was mostly lifted from the guile example directory *) + +open Swig +open Example + +let v = new_StringVector '() + +let _ = + for i = 0 to (Array.length Sys.argv) - 1 do + let str = (Sys.argv.(i)) to string in v -> push_back (str) + done + +let _ = _vec_write '(v) |
