File: runme.ml

package info (click to toggle)
swig 4.3.0-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 46,232 kB
  • sloc: cpp: 54,631; ansic: 29,122; java: 17,530; python: 12,505; cs: 10,369; ruby: 7,232; yacc: 6,477; makefile: 5,965; javascript: 5,520; sh: 5,415; perl: 4,187; php: 3,693; ml: 2,187; lisp: 2,056; tcl: 1,991; xml: 115
file content (57 lines) | stat: -rw-r--r-- 1,709 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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"