Re: [Vala] connecting non-gobject callbacks

2007-12-28 Thread Tilman Sauerbeck
Travis Watkins [2007-12-28 12:40]:
> On Dec 28, 2007 9:17 AM, Tilman Sauerbeck <[EMAIL PROTECTED]> wrote:
> > Hi,
> > I'm trying to write a client for XMMS2 in Vala.
> > XMMS2 doesn't use GObjects, but it uses callbacks in various places,
> > which makes it hard to use it in Vala.
> >
> > XMMS2 uses a struct called xmmsc_result_t, to which you can connect a
> > callback like this:
> >
> >   static void handler(xmmsc_result_t *res, void *user_data) {...}
> >
> >   xmmsc_result_t *res;
> >   xmmsc_result_notifier_set (res, handler, NULL);
> >
> > So eventually "handler" will be called with res and NULL. The straight
> > forward Vala bindings make it impossible to connect an instance method
> > as a notifier for a Xmms.Result, since the callback is always passed a
> > xmmsc_result_t* as the first argument, but Vala needs the first argument
> > to be a Vala object resp gobject. Connecting to class methods/static
> > methods works just fine, but it's just not sufficient.
> >
> 
> I think you're looking for the [InstanceLast] decorator. Then you just
> call xmmsc_result_notifier_set but only give it res and handler and
> your vala 'this' automatically gets put in for user_data.

Thanks Travis, that's exactly what I need :)
I saw InstanceLast being used before, but I never knew what it meant.
I think I'll contribute to the tutorial soonish..

Regards,
Tilman

-- 
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?


pgpfnvfIRtsgo.pgp
Description: PGP signature
___
Vala-list mailing list
Vala-list@gnome.org
http://mail.gnome.org/mailman/listinfo/vala-list


Re: [Vala] connecting non-gobject callbacks

2007-12-28 Thread Travis Watkins
On Dec 28, 2007 9:17 AM, Tilman Sauerbeck <[EMAIL PROTECTED]> wrote:
> Hi,
> I'm trying to write a client for XMMS2 in Vala.
> XMMS2 doesn't use GObjects, but it uses callbacks in various places,
> which makes it hard to use it in Vala.
>
> XMMS2 uses a struct called xmmsc_result_t, to which you can connect a
> callback like this:
>
>   static void handler(xmmsc_result_t *res, void *user_data) {...}
>
>   xmmsc_result_t *res;
>   xmmsc_result_notifier_set (res, handler, NULL);
>
> So eventually "handler" will be called with res and NULL. The straight
> forward Vala bindings make it impossible to connect an instance method
> as a notifier for a Xmms.Result, since the callback is always passed a
> xmmsc_result_t* as the first argument, but Vala needs the first argument
> to be a Vala object resp gobject. Connecting to class methods/static
> methods works just fine, but it's just not sufficient.
>

I think you're looking for the [InstanceLast] decorator. Then you just
call xmmsc_result_notifier_set but only give it res and handler and
your vala 'this' automatically gets put in for user_data.


-- 
Travis Watkins
http://www.realistanew.com
___
Vala-list mailing list
Vala-list@gnome.org
http://mail.gnome.org/mailman/listinfo/vala-list


Re: [Vala] connecting non-gobject callbacks

2007-12-28 Thread Xavier Bestel

Le vendredi 28 décembre 2007 à 16:17 +0100, Tilman Sauerbeck a écrit :
> Hi,
> I'm trying to write a client for XMMS2 in Vala.
> XMMS2 doesn't use GObjects, but it uses callbacks in various places,
> which makes it hard to use it in Vala.
> 
> XMMS2 uses a struct called xmmsc_result_t, to which you can connect a
> callback like this:
> 
>   static void handler(xmmsc_result_t *res, void *user_data) {...}
> 
>   xmmsc_result_t *res;
>   xmmsc_result_notifier_set (res, handler, NULL);
> 
> So eventually "handler" will be called with res and NULL.

Why didn't you try declaring the callbacks as xmmsc_result_t's methods ?
At first sight it could work.

Xav


___
Vala-list mailing list
Vala-list@gnome.org
http://mail.gnome.org/mailman/listinfo/vala-list


[Vala] connecting non-gobject callbacks

2007-12-28 Thread Tilman Sauerbeck
Hi,
I'm trying to write a client for XMMS2 in Vala.
XMMS2 doesn't use GObjects, but it uses callbacks in various places,
which makes it hard to use it in Vala.

XMMS2 uses a struct called xmmsc_result_t, to which you can connect a
callback like this:

  static void handler(xmmsc_result_t *res, void *user_data) {...}

  xmmsc_result_t *res;
  xmmsc_result_notifier_set (res, handler, NULL);

So eventually "handler" will be called with res and NULL. The straight
forward Vala bindings make it impossible to connect an instance method
as a notifier for a Xmms.Result, since the callback is always passed a
xmmsc_result_t* as the first argument, but Vala needs the first argument
to be a Vala object resp gobject. Connecting to class methods/static
methods works just fine, but it's just not sufficient.

Did anyone solve this problem before? We don't want to touch XMMS2, but
we'd like to solve this on the Vala side only :)

We tried to write a wrapper function in Vala that would allow us to pass
a Vala instance pointer around, too, but the problem is that you cannot
extend Vala classes (that are wrapping C structs) with Vala code.

ie if my vapi has this: "public class Xmms.Result" then you cannot
reopen the class in Vala and attach another method like this:
  public class Xmms.Result {
public void new_method () { ... }
  }

This last point might actually be what bug #480253 is about, but I'm not
sure (http://bugzilla.gnome.org/show_bug.cgi?id=480253#c2).

Any hints are appreciated, I hope this mail isn't too confusing :)

Regards,
Tilman

-- 
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?


pgpLbTsU0BkMa.pgp
Description: PGP signature
___
Vala-list mailing list
Vala-list@gnome.org
http://mail.gnome.org/mailman/listinfo/vala-list