2014-06-22 22 views
5

Il Vala Tutorial ha un example about DBus using anonymous methods.Come si chiudono le chiusure di Valas su Genie?

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 */ 

Sto cercando di riscrivere questo codice in Genie, ma non riusciva a convertire le ultime due righe. Lo Genie Tutorial ha solo 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 

Come utilizzare le definizioni di metodo anonime in una chiamata di metodo con Genie?

risposta

4

Penso che non ci sia modo. Devi chiamare un altro processo usando "def".

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

def reg() 
    pass 

def err() 
    print "error" 
3

Ciò non è possibile al momento:

https://bugzilla.gnome.org/show_bug.cgi?id=746704

Attualmente Genie supportano solo la sintassi lambda sconsigliata per segnali (+ =). Questa patch fornisce il supporto lambda nella maggior parte dei costrutti, l'unico requisito è che le parentesi graffe e le parentesi debbano essere bilanciate in modo indentato sui costrutti di linea multipli .