diff options
author | Haibo Huang <hhb@google.com> | 2019-10-08 15:48:26 -0700 |
---|---|---|
committer | Haibo Huang <hhb@google.com> | 2019-11-14 22:14:23 +0000 |
commit | 80b4251e302efb18c145a4786249d695397ed42a (patch) | |
tree | 12b9dec2513f7caa92e7835bc17ab16ae5635df6 /Examples/ocaml/class/runme.ml | |
parent | 189852d8cdfd5863c52ec7aa73affd926c5a3f43 (diff) | |
parent | 1e36f51346d95f8b9848e682c2eb986e9cb9b4f4 (diff) | |
download | swig-80b4251e302efb18c145a4786249d695397ed42a.tar.gz |
Upgrade swig to 'rel-4.0.1'llvm-r383902b
Also run autogen.sh to generate configure files.
Exempt-From-Owner-Approval: add myself to owners
Change-Id: I391aa20428836ae74dab8c8427627ca4dbc8ecf4
Diffstat (limited to 'Examples/ocaml/class/runme.ml')
-rw-r--r-- | Examples/ocaml/class/runme.ml | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/Examples/ocaml/class/runme.ml b/Examples/ocaml/class/runme.ml new file mode 100644 index 000000000..5e7b1f26c --- /dev/null +++ b/Examples/ocaml/class/runme.ml @@ -0,0 +1,57 @@ +(* file: runme.ml + + This file illustrates the proxy class C++ interface generated + by SWIG. *) + +open Swig +open Example + +let repr o = + Printf.sprintf "<%s at %#x>" (o -> ":classof" () as string) (o -> "&" () as int) + +(* ----- Object creation ----- *) + +let _ = print_endline "Creating some objects:" +let c = new_Circle '(10) +let _ = Printf.printf " Created circle %s\n" (repr c) +let s = new_Square '(10) +let _ = Printf.printf " Created square %s\n" (repr s) + +(* ----- Access a static member ----- *) + +let _ = Printf.printf "\nA total of %d shapes were created\n" (_Shape_nshapes '() as int) + +(* ----- Member data access ----- *) + +(* Set the location of the object *) + +let _ = c -> "[x]" (20) +let _ = c -> "[y]" (30) + +(* Temp var to work around a swigp4 bug (it doesn't properly handle "-" in some cases). *) +let arg = (-10. to float) +let _ = s -> "[x]" (arg) +let _ = s -> "[y]" (5) + +let _ = print_endline "\nHere is their current position:" +let _ = Printf.printf " Circle = (%f, %f)\n" (c -> "[x]" () as float) (c -> "[y]" () as float) +let _ = Printf.printf " Square = (%f, %f)\n" (s -> "[x]" () as float) (s -> "[y]" () as float) + +(* ----- Call some methods ----- *) + +let _ = print_endline "\nHere are some properties of the shapes:" + +let _ = List.iter (fun o -> + Printf.printf " %s\n" (repr o); + Printf.printf " area = %f\n" (o -> area () as float); + Printf.printf " perimeter = %f\n" (o -> perimeter () as float) + ) [c; s] + +let _ = print_endline "\nGuess I'll clean up now" + +(* Note: this invokes the virtual destructor *) +let _ = c -> "~" () +let _ = s -> "~" () + +let _ = Printf.printf "%d shapes remain\n" (_Shape_nshapes '() as int) +let _ = print_endline "Goodbye" |