Version française
Home     About     Download     Resources     Contact us    
Browse thread
C wrappers and callbacks from Ocaml to C and back to Ocaml
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Goswin von Brederlow <goswin-v-b@w...>
Subject: Re: [Caml-list] C wrappers and callbacks from Ocaml to C and back to Ocaml
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