Browse thread
[Caml-list] Caml productivity.
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Xavier Leroy <xavier.leroy@i...> |
| Subject: | Re: [Caml-list] CamlIDL and function pointers |
> How would one annotate the following C struct for camlidl:
>
> typedef struct funp {
> int i;
> void (*funp_fun) ();
> } funp_t;
>
> Is it possible? Looking at the specs I don't see how one can have a
> field that is a pointer to a function. Any ideas, or pointers (no pun
> intended) to examples?
CamlIDL, like the DCE and Microsoft IDL from which it derives, doesn't
support exchanging function pointers between C and Caml. Your best
bet is to declare funp_t as an abstract type in the IDL file:
typedef [abstract] struct funp * funp_t;
and export C functions that do what you need to do on this funp_t
type, e.g.
void invoke(funp_t arg);
where "invoke" is defined directly in C somewhere else:
void invoke(funp_t arg) { arg->funp_fun(arg->i); }
Of course, you won't be able to, say, construct a funp_t where the
function part is actually a Caml function. If you need that kind of
callback mechanism, you'll have to write some of the stub code by hand,
using Caml's callback functions. Alternatively, if you can re-shape
your struct funp till it looks like a COM interface, you could then use
the CamlIDL "interface" declaration and get Caml->C and C->Caml calls.
Hope this helps,
- Xavier Leroy
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners