本文介绍了如何Valas闭包映射到Genie?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有一个。
Bus.own_name (BusType.SESSION,org.example.DemoService,/ *要注册的名称* /
BusNameOwnerFlags.NONE,/ * flags * /
on_bus_aquired,/ *注册成功时的回调函数* /
()=> {},/ *名称注册的回调成功* /
()=> stderr.printf(Could not acquire name\ / * callback on name lost * /
我试图在Genie中重写这个代码,管理转换最后两行。 只有。
f.my_event + = def(t,a)
print检测到值为%d的事件,a
如何在Genie的方法调用中使用匿名方法定义?
解决方案
我认为没有办法。您必须使用def调用另一个进程。
Bus.own_name(BusType.SESSION,org.example.DemoService
pre>
BusNameOwnerFlags.NONE,
on_bus_aquired,
reg,
err);
def reg()
pass
def err()
printerror
The Vala Tutorial has an 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 */
I am trying to rewrite this code in Genie, but could not manage to convert the two last lines. The Genie Tutorial only has 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
How do I use anonymous method definitions in a method call with Genie?
解决方案I think there is not way. You must call another process using "def".
Bus.own_name (BusType.SESSION, "org.example.DemoService", BusNameOwnerFlags.NONE, on_bus_aquired, reg, err); def reg() pass def err() print "error"
这篇关于如何Valas闭包映射到Genie?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!