Joel Reymont <
joelr1@...> writes:
> Suppose I have a C++ class with a bunch of methods that act as callbacks.
>
> My callbacks will be hit if I derive the class and implement the
> methods I'm interested in.
>
> Now, I would like to wrap this class from OCaml.
>
> This is straightforward from using OCaml classes (section 18.3.5 of
> the manual) but is there a way to implement this using modules?
>
> I don't think this is possible but would like to confirm.
>
> Thanks, Joel
From the top of my head:
module M = struct
type t
external foo : t -> unit = "caml_mine_M_foo"
end
class M {
void foo(void) { }
};
value caml_mine_M_foo(value ml_m) {
CAMLparam1(ml_m);
M *m = (M*)ml_m;
m->foo();
CAMLreturn Val_unit;
}
Wouldn't that do?
It gets harder with inheritance, when you have modules A, B, C for the
different classes and want to be able to pass a C.t to a function
expecting a B.t. You will need to declare a C.as_b function and such.
MfG
Goswin
--
Caml-list mailing list. Subscription management and archives:
https://sympa-roc.inria.fr/wws/info/caml-listBeginner's list:
http://groups.yahoo.com/group/ocaml_beginnersBug reports:
http://caml.inria.fr/bin/caml-bugs