On 22. Apr, 2010, at 15:48 , Abderrahim Kitouni wrote:

> Hi,
> 
> 2010/4/22 Michael Wild <[email protected]>:
>> Hi all
>> 
>> I am currently trying to generate bindings for a API which has some
>> peculiarities which I can't seem to find any solution for.
>> 
>> 1) Constructor function: Say I would like to use a C function as the 
>> constructor for a class (as e.g. newwin is used in curses.vapi). However, 
>> that C function does not return the allocated and initialized object in the 
>> return value, but as the first argument. The return value is an error code 
>> instead. How would I handle this?
> I don't understand this, does the function still alocate the instance,
> or does it just initialize it?

It does both, it just doesn't return the result in the return argument, but in 
one of the parameters. I found an example with the same issue, but I don't 
understand how Vala can be doing the right thing. Looking at zlib.vapi I see

[CCode (cname = "z_stream", destroy_function = "deflateEnd")]
public struct DeflateStream : Stream {
    [CCode (cname = "deflateInit")]
    public DeflateStream (int level = Level.DEFAULT_COMPRESSION);
    // ...
}

but deflateInit has the following (sanitized) signature:

int deflateInit(z_stream *strm, int level);

How does Vala know that it must pick the first argument and not the return 
value?


> 
>> 2) Delegates: The C API defines a number of callback functions, most of 
>> which take some user-defined data as an argument one registers along with 
>> the callback function. However, the user data is often neither the first nor 
>> the last argument. How can I wrap this?
> [CCode (instance_pos=)]
> you can use things like 3.1 for "after the 3rd argument" and 3.9 for
> "before the 4th argument"
> 

Cool, just what I need (I hope the semantics given in below reference are still 
valid)...

>> 3) Is there any comprehensive attributes reference somewhere? The Vala 
>> reference (draft version) doesn't really say much, and actually seems to be 
>> quite a bit stale.
> 
> Some time ago, someone posted a "work in progress" here [1], not sure
> if it has been added to the wiki or something.

Certainly very valuable information (and IMHO hard to find...)

> 
> Regards,
> Abderrahim
> 
> [1] http://mail.gnome.org/archives/vala-list/2009-December/msg00019.html


Thanks a lot!

Michael

_______________________________________________
vala-list mailing list
[email protected]
http://mail.gnome.org/mailman/listinfo/vala-list

Reply via email to