Re: [Vala] Creating a binding for a non-glib library and using delegate to map a function pointer
- From: Abderrahim Kitouni <a kitouni gmail com>
- To: Luca Dionisi <luca dionisi gmail com>
- Cc: vala-list gnome org
- Subject: Re: [Vala] Creating a binding for a non-glib library and using delegate to map a function pointer
- Date: Mon, 14 Mar 2011 22:58:28 +0100
في ح، 13-03-2011 عند 17:54 +0100 ، كتب Luca Dionisi:
Another important point: you shouldn't use has_target=false if the
library you are binding has user_data arguments, so your
FunctionDelegate should be defined as
public delegate void* FunctionDelegate ();
And generally, you should try to avoid using void* if possible. For
example, if it makes sense for your library, you can use a generic
delegate.
I don't get how this would map a prototype like:
void foobar(void *(*f)(void *), void *user_data);
We have a 'void *(*f)(void *)', it's a callback that only takes a
user_data parameter (which is implicit in vala) and returns a pointer,
at first it would be bound as:
public delegate void* FunctionDelegate ();
public void foobar (FunctionDelegate f);
then, if the type of the return value can be known "at compile time",
i.e. the delegate isn't supposed to return a random pointer, you can
convert this to generics using something like (untested):
public delegate G FunctionDelegate<G> ();
public void foobar<G> (FunctionDelegate<G> f);
To be explicit in real world, I want to make a binding for GNU Pth. In
their header there is:
extern pth_t pth_spawn(pth_attr_t, void *(*)(void *), void *);
It's better to look at their documentation rather than their header :-)
Otherwise, I think what I said above applies.
You can also take a look at how this is done in the GLib threading API
for inspiration ;-)
http://git.gnome.org/browse/vala/tree/vapi/glib-2.0.vapi#n1777
HTH,
Abderrahim
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]