Upstream version 1.3.40
[profile/ivi/swig.git] / Examples / ocaml / string_from_ptr / example_prog.ml
1 (* foo_program.ml -- the program using foolib *)
2
3 open Swig    (* Give access to the swig library *)
4 open Foolib  (* This is the name of your swig output *)
5
6 let results = _foo '()  (* Function names are prefixed with _ in order to make
7                            them lex as identifiers in ocaml.  Consider that
8                            uppercase identifiers are module names in ocaml.
9                            NOTE: the '() syntax is part of swigp4.  You can do:
10                            let results = _foo C_void *)
11
12 (* Since your function has a return value in addition to the string output,
13    you'll need to match them as a list *)
14
15 let result_string =
16   match results with 
17     C_list [ C_string result_string ; C_int 0 ] -> (* The return value is
18         last when out arguments appear, but this too can be customized.
19         We're also checking that the function succeeded. *)
20       result_string
21   | _ -> raise (Failure "Expected string, int reply from _foo")
22       
23 let _ = print_endline result_string