Re: [Vala] Properly wrapping callbacks
- From: Jürg Billeter <j bitron ch>
- To: Frederik <scumm_fredo gmx net>
- Cc: vala-list <vala-list gnome org>
- Subject: Re: [Vala] Properly wrapping callbacks
- Date: Mon, 26 Jan 2009 11:37:06 +0100
On Mon, 2009-01-26 at 11:32 +0100, Frederik wrote:
Frederik wrote:
Michael 'Mickey' Lauer wrote:
Hi,
I'm working on my first binding for a non-gobject library -- please see
gsm0710_p.h.
My current vapi is also attached. I'm struggling with setting the callback
pointers now. How should the callbacks in my .vala object be defined so that
I can set them via e.g.
<callback>
var ctx = new Context();
ctx.at_command = <callback>
Cheers,
Mickey.
You should make your delegate non-static, since an instance gets passed.
In your case the instance gets passed as first parameter and not as last
parameter, so you must add [CCode [instance_pos = 0)]. And 'char*'
translates to 'string' in Vala.
[CCode [instance_pos = 0)]
public delegate int at_command_t (string command);
However, if it is meant as source object for some kind of event and not
as instance you should mark it as static and pass the context explicitly:
public static delegate int at_command_t (Context ctx, string command);
Yes, this is better as, in this library, the first callback parameter
does not represent the instance of the user-defined handler (usually
called user_data), it's always a pointer to the context.
Jürg
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]