Re: [Vala] Binding questions



On Mon, 16 Feb 2009 00:58:16 -0200
Matías De la Puente
<mfpuente ar gmail com> wrote:

if is a typedef of XID->CARD32->unsigned long you can also do this:

[CCode (cname="CARD32")]
public struct CARD32 : ulong {}

[CCode (cname="XID")]
public struct XID : CARD32 {}

[CCode (cname="ColorMap")]
public struct ColorMap: XID {}

Try both ways and see what C code valac generates. If the parameter is
passed by value add [SimpleType].

Ahh.  That worked beautifully, and casting is easily done.  Very cool.

One other question; if you have a C function that returns a pointer to
an array of items (say, the return type is "int *", and so in Vala
you'd say int[]), it seems to assume that the last (implicit) parameter
is the length of the array.  In other words, for the Xlib entry point
int *XListDepths(Display *d, int screen_number, int *count_return), I
have to define:

  [CCode(cname = "XListDepths")]
  public int[] get_all_depths(int screen_number);

And Vala will turn this into a call to:

  XListDepths (d, screen, &_tmp0)

... creating "&_tmp0" of type gint on its own.  What happens if there
is no such parameter (say, the list is returned and you get the count
by doing pointer arithmetic until you reach a sentinel value of some
sort), or it is in a different location (say, the first or second
parameter in the list)?

Is there somewhere in the documentation where these sorts of "edge"
cases are covered, perchance?

        --- Mike

-- 
My sigfile ran away and is on hiatus.
http://www.trausch.us/





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