From: Goswin von Brederlow <goswin-v-b@web.de>
To: caml-list@inria.fr
Subject: Re: [Caml-list] C wrappers and callbacks from Ocaml to C and back to Ocaml
Date: Fri, 07 Aug 2009 01:38:30 +0200 [thread overview]
Message-ID: <87r5voa4y1.fsf@frosties.localdomain> (raw)
In-Reply-To: <20090807071731.bfd0d34b.mle+ocaml@mega-nerd.com> (Erik de Castro Lopo's message of "Fri, 7 Aug 2009 07:17:31 +1000")
Erik de Castro Lopo <mle+ocaml@mega-nerd.com> writes:
> Hi all,
>
> I'm wrapping some C code that requires me to define a struct in Ocaml
> like this:
>
> type xt = { f : xt -> a }
>
> and then pass the struct to C which stores it, and later the C needs
> to find function f, call it from C, passing it the Ocaml xt struct.
>
> Anyone have any clues on how to do this? I have most of the rest of
> the C wrapper sorted out, its just this thats causing me any difficulty.
>
> Cheers,
> Erik
Well, you just do. A structure is a value like anything else.
What you have to wath out for is the GC. If you store the value
somewhere then you have to tell the GC about it by registering it as a
new root. And when you are done with it you need to unregister it.
As for access the docs tell you about how to access fields of a record
and also how to invoke a ocaml closure from C. Just read the relevant
sections from the chapter about interfacing ocaml and C.
MfG
Goswin
next prev parent reply other threads:[~2009-08-06 23:38 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-08-06 21:17 Erik de Castro Lopo
2009-08-06 23:38 ` Goswin von Brederlow [this message]
2009-08-07 4:23 ` [Caml-list] " Erik de Castro Lopo
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=87r5voa4y1.fsf@frosties.localdomain \
--to=goswin-v-b@web.de \
--cc=caml-list@inria.fr \
/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