Re: [Vala] using a non-glib c library



On Thu, Sep 24, 2009 at 18:11:59 -0500, Mr. Maxwell . wrote:
ID3Lib defines numerous enums. Here's an example

typedef enum _ID3_TextEnc ID3_TextEnc; enum _ID3_TextEnc
{
  ID3TE_NONE = -1,
  ID3TE_ISO8859_1,
  ID3TE_UTF16,
  ID3TE_UTF16BE,
  ID3TE_UTF8,
  ID3TE_NUMENCODINGS,
  ID3TE_ASCII = ID3TE_ISO8859_1,
  ID3TE_UNICODE = ID3TE_UTF16
};

I'm not to sure how to bind them and I'm not sure how to use them after
I bind them. Any ideas? 

[CCode(cname = "ID3_TextEnc", cprefix = "ID3TE_")]
enum {
    NONE,
    ISO8859_1,
    UTF16,
    UTF16BE,
    UTF8,
    NUMENCODINGS,
    ASCII,
    UNICODE
}

cname is the name of the typedef, cprefix is the common prefix you want to
strip from all constants. Than go the constants, without values, because vala
will just emit the corresponding C names and let C compiler sort out the
values.

If the constants are supposed to be ored together (which is not this case),
prepend a [Flags] annotation (that enables using & and | operators with the
enum).

One more thing, a lot of the functions return C style strings, (char *) are
they the same as vala strings? (so I can replace char * with string?)

Yes, "string" in vala corresponds to "char *" in C. You will just have to
find out which strings you have to free and which not and mark the later as
"weak". All const ones will be weak, but some others might too.

-- 
                                                 Jan 'Bulb' Hudec <bulb ucw cz>



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