diff --git a/Examples/test-suite/ocaml/dynamic_cast_runme.ml b/Examples/test-suite/ocaml/dynamic_cast_runme.ml new file mode 100644 index 000000000..54391d9a0 --- /dev/null +++ b/Examples/test-suite/ocaml/dynamic_cast_runme.ml @@ -0,0 +1,9 @@ +open Swig +open Dynamic_cast + +let f = new_Foo '() +let b = new_Bar '() + +let x = f -> blah () +let y = b -> blah () +assert (_do_test '(y) as string = "Bar::test") diff --git a/Lib/ocaml/typemaps.i b/Lib/ocaml/typemaps.i index 4475707d6..a781838ca 100644 --- a/Lib/ocaml/typemaps.i +++ b/Lib/ocaml/typemaps.i @@ -307,6 +307,11 @@ SIMPLE_MAP(unsigned long long,caml_val_ulong,caml_long_val); $2 = ($2_ltype) caml_string_len($input); } +%typemap(out) SWIGTYPE *DYNAMIC, SWIGTYPE &DYNAMIC { + swig_type_info *ty = SWIG_TypeDynamicCast($1_descriptor, (void **)&$1); + $result = SWIG_Ocaml_ptr_to_val("create_$ntype_from_ptr", (void *)$1, ty); +} + /* Array reference typemaps */ %apply SWIGTYPE & { SWIGTYPE ((&)[ANY]) } %apply SWIGTYPE && { SWIGTYPE ((&)[ANY]) }