swig/Examples/ocaml/callback/runme.ml
Zackery Spytz 071803f000 [OCaml] Fix segfaults when too few arguments are passed to a function
Prevent segfaults when too few arguments are passed to a function.

Length checks are not needed for the wrappers of overloaded
functions -- the generated dispatch function already checks.

Add default_args_runme.ml.

Fix minor errors in some runtime tests.  Extra args were being passed
in some cases.
2019-02-15 01:17:15 -07:00

30 lines
904 B
OCaml

(* file: runme.ml
This file illustrates cross-language polymorphism using directors. *)
open Swig
open Example
let new_OCamlCallback ob meth args =
match meth with
| "run" -> print_endline "OCamlCallback.run()"; C_void
| _ -> (invoke ob) meth args
let caller = new_Caller '()
let _ = print_endline "Adding and calling a normal C++ callback"
let _ = print_endline "----------------------------------------"
let callback = new_Callback '()
let _ = caller -> "setCallback" (callback)
let _ = caller -> "call" ()
let _ = caller -> "delCallback" ()
let _ = print_endline "\nAdding and calling an OCaml callback"
let _ = print_endline "------------------------------------"
let callback = new_derived_object new_Callback (new_OCamlCallback) '()
let _ = caller -> "setCallback" (callback)
let _ = caller -> "call" ()
let _ = caller -> "delCallback" ()
let _ = print_endline "\nOCaml exit"