How do Valas closures map to Genie?
Asked Answered
S

2

6

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?

Slant answered 22/6, 2014 at 14:26 Comment(0)
D
4

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"
Diphase answered 9/2, 2015 at 14:56 Comment(0)
K
4

This isn't possible at the moment:

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

Currently Genie only support the deprecated lambda syntax for signals (+=). This patch provides lambda support in most constructs, the only requirement is that braces and parens need to be indent-balanced on multiple line constructs.

Khachaturian answered 14/7, 2015 at 10:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.