Re: [Vala] Creating a binding for a non-glib library and using delegate to map a function pointer



On Sat, Mar 12, 2011 at 12:38 PM, Abderrahim Kitouni
<a kitouni gmail com> wrote:
في ج، 11-03-2011 عند 16:25 +0100 ، كتب Luca Dionisi:
Perhaps I got the point where I was wrong.

On Fri, Mar 11, 2011 at 12:42 PM, Luca Dionisi <luca dionisi gmail com> wrote:
First pass, I prepared a direct mapping vapi.
 libfoo.vapi    [http://pastebin.com/rZb6JqAZ]
 [IMPORTANT note: if I don't miss something, I have
 [to create a delegate, named FunctionDelegate, in the vapi
 [file in order to map the function pointer argument.

Another way to do that is to define the delegate in another vala
source file and include it in the compilation where libfoo.vapi is
used.
I think it would be better to just create a new header that you
reference in the vapi, it would be easier to distribute with your
wrapping library.

I'll try to do that.


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);

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 *);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]