[Vala] non-gobject generics



I have written a simple API in C for managing lists of pointers which is going to
be used as a simple interface for iterators.

 http://radare.nopcode.org/hg/radare2/file/8e9c1ea44114/libr/util/iter.c

The same functions are written as defines in the iter.h file libr/include/iter.h to
inline as much as possible by using the external lib.

This API works fine with the C example, but I tried to do the VAPI implementing this
as a Generic compact class. The definition looks like:

   [Compact]
   [CCode (cprefix="r_iter_")]
   public class Iter<G> {
       public Iter (int size);
       public unowned G get ();
       public unowned G next ();
       public unowned G next_n (int idx);
       public unowned G prev ();
       public void delete ();
       public G first ();
       public bool last ();
       // TODO: foreach()
       public G free ();
       public void set (int idx, G data);
   }

But I get this error while trying to compile the test program:
using Radare;

-------------------
public class IterableObject : Radare.Iter {
       public string name { get;set; }

       public IterableObject(string name) {
               this.name = name;
       }
}

Radare.Iter<IterableObject> get_iter_list ()
{
Radare.Iter<IterableObject> list = new Radare.Iter<IterableObject>(3);
       list.set(0, new IterableObject("patata"));
       list.set(1, new IterableObject("barata"));
       list.set(2, new IterableObject("lalata"));
       return list;
}

void main()
{
       Radare.Iter<IterableObject> foo = get_iter_list ();
       while (!foo.last ()) {
               unowned IterableObject io = foo.get ();
               stdout.printf("name: %s\n", io.name);
       }
}
-------------------

pancake flubox:~/prg/radare2/libr/vapi/t$ valac iter.vala --pkg r_util
iter.vala:6.2-6.22: warning: unable to chain up to base constructor requiring arguments
       public IterableObject(string name) {
       ^^^^^^^^^^^^^^^^^^^^^
iter.vala:3.1-3.41: error: derived compact classes may not have instance fields
public class IterableObject : Radare.Iter {
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Compilation failed: 1 error(s), 1 warning(s)



Looks like vala does not supoprt to implement non-gobject (aka compact) generic classes, or
at least i cannot inherit such methods from there.

Is this a bug? or I am doing something incorrect?

Thanks!

--pancake



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