Just a scratch of idea: class array<T> { [CCode (snippet = "int i; while(((T)this)[i]) i++; return i;")] public int get_length(); [CCode (snippet = "gpointer * rt; while((T)(this)[i]) i++; result.length = i; rt = g_new0(T, i); for(i=0; i<result.length; i++) rt[i] = this[i]); return rt;")] public array duplicate(); [CCode (snippet = "return this[id];")] public T element(int id); [CCode (snippet = "g_free(this);")] public void free(); }
If as we distinguish <T> with <strong T> in generics, class array<strong T> { [CCode (snippet = "int i; while(((T)this)[i]) i++; return i;")] public int get_length(); [CCode (snippet = "gpointer * rt; while((T)(this)[i]) i++; result.length = i; rt = g_new0(T, i); for(i=0; i<result.length; i++) rt[i] = this[i]); return rt;")] public array duplicate(); [CCode (snippet = "return this[id];")] public T element(int id); [CCode (snippet = "while(this[i]) { T.unref(this[i++]); } g_free(this);")] public T free(); } equvilently class array becomes where vala look up the code to use to do the quirks. At least we can pull them out from vala binaries. Similar can be done with GList. and other libraries. On Fri, 2008-08-22 at 11:21 +0200, Jürg Billeter wrote: > On Fri, 2008-08-22 at 05:09 -0400, Yu Feng wrote: > > On Fri, 2008-08-22 at 10:44 +0200, Jürg Billeter wrote: > > > Maybe I'm just missing an interesting use case, however, I currently > > > fail to see where the snippet approach makes it more comfortable to > > > write or use bindings. Can you provide examples where you think that it > > > makes more sense to handle it in a snippet instead of the compiler code? > > > I'm not convinced by the g_strv_length example as this would clutter the > > > bindings too much, in my opinion. > > > > Again it is for rare cases. I am thinking hard to make the snipples > > working well, and I'll collect more cases later. I don't expect there to > > be much though. Should it be much fewer than [NoArrayLength] stuff. > > Ok, as you agree that the null-terminated arrays should be handled, your > g_strv_length example is not a real use case for the snippet support. > Can you provide a concrete example where you think it makes more sense > to use a CCode snippet than anything else? > > > BTW: I found a way to kill the vast number static wrappers in DBus > > dynamic methods. File a new bug? > > Sure. > > Cheers, > Jürg > _______________________________________________ Vala-list mailing list Vala-list@gnome.org http://mail.gnome.org/mailman/listinfo/vala-list