On Sun, 2016-02-21 at 00:30 +0100, mar...@saepia.net wrote:
> Hello,
> 
> I am writing a program where I would like to have possibility to add
> arbitrary amount of callbacks which must be delegates.
> 
> I would like to store them somewhere, and then call one after another
> when
> it's appropriate.
> 
> My first step was
> 
> public class Test : Object {
> 
>   public void delegate MyFunc();
>   private List<MyFunc> funcs = new List<MyFunc>();
> 
>   public void add(MyFunc func) {
>     this.funcs.append(func);
>   }
> }
> 
> But vala compiler complains about the fact that delegates with
> targets
> can't be used as generics.
> 
> Is there any clear way of doing this at the moment (I am using vala
> 0.30).

You would need to create a type to hold the delegate and use that as
your generic type argument instead of the delegate itself.  Something
like

public class Test : Object {
  public void delegate MyFunc();

  private class MyFuncData {
    public MyFunc func;

    public MyFuncData (owned MyFunc func) {
      this.func = (owned) func;
    }
  }

  private List<MyFunc> funcs = new List<MyFunc>();

  public void add (owned MyFunc func) {
    this.funcs.append (new MyFuncData ((owned) func));
  }
}

Attachment: signature.asc
Description: This is a digitally signed message part

_______________________________________________
vala-list mailing list
vala-list@gnome.org
https://mail.gnome.org/mailman/listinfo/vala-list

Reply via email to