From: Goswin von Brederlow <goswin-v-b@web.de>
To: Joel Reymont <joelr1@gmail.com>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] using modules to wrap c++ classes
Date: Thu, 03 May 2012 15:35:49 +0200 [thread overview]
Message-ID: <871un1z8sq.fsf@frosties.localnet> (raw)
In-Reply-To: <CAOQwdX1f_RvxeV=NZPaN9-XwSNw3bg_nWzhFMf6Qga0L5Btt9Q@mail.gmail.com> (Joel Reymont's message of "Thu, 3 May 2012 13:22:49 +0100")
Joel Reymont <joelr1@gmail.com> 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
next prev parent reply other threads:[~2012-05-03 13:35 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-05-03 12:22 Joel Reymont
2012-05-03 13:35 ` Goswin von Brederlow [this message]
2012-05-03 13:56 ` Joel Reymont
2012-05-03 14:27 ` Gabriel Scherer
2012-05-03 15:02 ` Joel Reymont
2012-05-03 18:41 ` Joel Reymont
2012-05-03 19:20 ` Joel Reymont
2012-05-04 8:43 ` Goswin von Brederlow
2012-05-04 17:23 ` Joel Reymont
2012-05-05 12:39 ` Goswin von Brederlow
2012-05-05 14:11 ` Joel Reymont
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=871un1z8sq.fsf@frosties.localnet \
--to=goswin-v-b@web.de \
--cc=caml-list@inria.fr \
--cc=joelr1@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox