Version française
Home     About     Download     Resources     Contact us    
Browse thread
camlp4 question
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Martin Jambon <martin_jambon@e...>
Subject: Re: [Caml-list] camlp4 question
On Thu, 8 Sep 2005, Christophe Raffalli wrote:

> I am writing a tool to facilitate the use of callback of camlfunction from C. 
> I have a first prototype running for lablGlut, but I want to make it nicer 
> using camlp4 (this extension should produce automatically the C wrapper for 
> each callback, the user will only have to compile the produced C file).
>
> The pb is that I need to retrieve information given in one module from 
> another. The minimum I need to do is to search for the path given to ocamlc 
> (the -I options) from camlp4 code, but I would prefer a better way, and I do 
> not know how to retrive this PATH anyway.

Maybe write a script which would transmit the -I options to camlp4o and to 
ocamlopt/ocamlc (each camlp4 loadable module can define additional options 
to pass to camlp4/camlp4o)

Martin

>
> Here is an example to illustrate what I need (the type 'a callback is a type 
> to a C wrapper for a function of type 'a) :
>
> -- file glut.ml, part of the lablGlut library --
>
> ...
>
> let visibility_state_of_int = function
>    0 ->  NOT_VISIBLE
>  | 1 -> VISIBLE
>  | _ -> raise (BadEnum "visibility_state")
>
> REGISTER_CONVERSION visibility_state_of_int
>
> external visibilityFunc :
>  cb:(state:visibility_state_t->unit) callback->unit
>   = "ml_glutVisibilityFunc"
>
> ...
>
> -- file test.ml an example using lablGlut --
>
> open Glut
>
> ...
>
> let state_changed ~state =
>  match value with
>    NOT_VISIBLE -> printf "window not visible."; print_newline()
>  | VISIBLE -> printf "window not visible."; print_newline()
>
> MAKE_WRAPPER state_changed state_changed_cb
> (* here I need to search for the convertion for the type 
> visibility_state_of_int which was defined in glut.ml to make the
> C wrapper state_changed_cb : (visibility_state_of_int -> unit) callback *)
>
> let _ = Glut.visibilityFunc state_changed_cb
>
> ...
>
> Can someone help ?
>
> _______________________________________________
> Caml-list mailing list. Subscription management:
> http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
> Archives: http://caml.inria.fr
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
>

--
Martin Jambon, PhD
http://martin.jambon.free.fr