How to tweak the variables, which a Lambda expression in Vala captures?

前端 未结 1 1772
时光取名叫无心
时光取名叫无心 2021-01-28 20:07

How to capture this only weakly in a anonymous function?

I couldn\'t find anything in the docs regarding whether (or how) the variables cap

相关标签:
1条回答
  • 2021-01-28 20:46

    Inside a lambda, no. The standard approach is this:

    class Foo : Whatever {
    
      public Foo {
        unowned Foo unowned_this = this;
        this.bar_signal.connect(unowned_this.bar_handler);
      }
      private void bar_handler() {
        ...
      }
    }
    

    This doesn't capture a reference to this, but you also cannot capture any other variables.

    0 讨论(0)
提交回复
热议问题