Re: [Vala] Binding questions



Hello Michael,

2009/2/15 Michael B. Trausch <mike trausch us>
I am trying to create a small Xlib binding for Vala, with a little bit
of difficulty.  I think I just don't understand what it is that I am
doing fully.

Starting with what Frederik gave as an initial set of code, I have so
far come up with:

[CCode(cprefix = "X", cheader_filename = "X11/Xlib.h")]
namespace XLib {
       [Compact]
       [CCode(cname = "Display", free_function = "XCloseDisplay")]
       public class Display {
               [CCode(cname = "XOpenDisplay")]
               public Display(string? display_name = null);

               [CCode(cname = "XDefaultScreen")]
               public int get_default_screen();

               [CCode(cname = "XBlackPixel")]
               public long get_black_pixel(int screen_number);

               [CCode(cname = "XWhitePixel")]
               public long get_white_pixel(int screen_number);

               [CCode(cname = "XConnectionNumber")]
               public int get_connection_number();

               [CCode(cname = "XDefaultColormap")]
               public ColorMap get_default_colormap(int screen_number);

               [CCode(cname = "XAllPlanes")]
               public static long get_all_planes();
       }
}

Now, the problem is the return value for XDefaultColormap.  This is
really a typedef to XID, which itself is a typedef to CARD32, which is
in turn a typedef to "unsigned long".  I could just declare it to be an
ulong, but it'd seem that there should be some way to do this in a
type-safe manner.  Is there something simple that I am just not getting?

You can define the ColorMap like this:

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

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].

See gl.vapi in http://live.gnome.org/Vala/ExternalBindings there's some definition that I use for GLboolean, GLint, etc

Matias



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