[Vala] Making a class iterable from VAPI bindings
- From: Calvin Walton <calvin walton kepstin ca>
- To: vala-list gnome org
- Subject: [Vala] Making a class iterable from VAPI bindings
- Date: Sat, 15 Oct 2011 16:47:33 -0400
Hi everyone.
I'm currently writing up a .vapi file to create bindings for the
libmusicbrainz4 library's C interface (download at
http://musicbrainz.org/doc/libmusicbrainz - online documentation at
http://users.musicbrainz.org/~luks/docs/libmusicbrainz4/mb4__c_8h.html )
It has a list type, which is defined as
typedef void* Mb4ArtistList;
typedef void* Mb4Artist;
int mb4_artist_list_size(Mb4ArtistList l);
Mb4Artist mb4_artist_list_item(Mb4ArtistList l, int i);
...
Right now, my bindings for this look like
[CCode (cheader_filename = "musicbrainz4/mb4_c.h")]
namespace Mb4 {
[Compact]
public class ArtistList {
[CCode (cname = "mb4_artist_list_item")]
public unowned Artist? get(int item);
public int length {
[CCode (cname = "mb4_artist_list_size")]
get;
}
}
}
which seems to work, allowing it to be accessed like an array
(artist_list[2] and artist_list.length work). But I can't use it with
the foreach loop, because it doesn't have an iterator method - even
though you can use foreach on an array. I assume this is special cased?
Is there any way to add an iterator class to my .vapi file so I can use
foreach, or any plans to allow foreach on types which provide a length
property and get(index) method?
--
Calvin Walton <calvin walton kepstin ca>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]