lambda - Valas 闭包如何映射到 Genie?

标签 lambda closures vala genie

Vala Tutorial有一个 example about DBus using anonymous methods .

Bus.own_name (BusType.SESSION, "org.example.DemoService", /* name to register */
              BusNameOwnerFlags.NONE, /* flags */
              on_bus_aquired, /* callback function on registration succeeded */
              () => {}, /* callback on name register succeeded */
              () => stderr.printf ("Could not acquire name\n")); /* callback on name lost */

我正在尝试在 Genie 中重写此代码,但无法转换最后两行。 Genie Tutorial只有an example on how to use a closure to define an event handler .
f.my_event += def (t, a)
    print "event was detected with value %d", a

如何在 Genie 的方法调用中使用匿名方法定义?

最佳答案

我认为没有办法。您必须使用“def”调用另一个进程。

Bus.own_name (BusType.SESSION, "org.example.DemoService", 
          BusNameOwnerFlags.NONE, 
          on_bus_aquired, 
          reg,
          err);

def reg()
    pass

def err()
    print "error"

关于lambda - Valas 闭包如何映射到 Genie?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24352222/

相关文章:

amazon-web-services - DynamoDB : UpdateItem, 忽略 ExpressionAttributeValues 中的空值

工具栏中的组合框

c - Vala(类 C# 语言)编译成 C?

c# - Lambda 和类型推断

lambda - 查找 Prolog 对列表中的键

Java 流 "forEach"但不消耗流

ios - 为什么相同的闭包类型没有被分配

JavaScript 闭包 : Pratical Closures example in MDN

ios - 我是否需要在 UIAlertController 的操作完成处理程序中弱捕获 self

gtk3 - 如何在 anjuta 项目中包含资源文件