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/