Re: [Vala] this = Object



If you're trying to use a delegate from C, you need to be aware of the
delegate's target, which is a hidden parameter to Vala code but visible in
C.

If you compile your code with the --save-temps flag enabled, you can see how
a delegate is constructed in C.  For example:

delegate void Callback(int32 i);

Becomes this in the .c:

typedef void (*Callback) (gint32 i, void* user_data);

The user_data is the target (in Vala-parlance).  Your C code should invoke
the callback like this:

Callback _cb = cb;
...
_cb (i, obj);

Rob's right, you can't (or shouldn't) assign to "this" in Vala.  When you
invoke the callback with obj as the user_data, Vala's internal code will use
it as the "this" reference.

A useful reference if you're making a VAPI:
http://live.gnome.org/Vala/Bindings/MetadataFormat

-- Jim

On Tue, Sep 28, 2010 at 5:10 AM, Cyrille Colin <colin univ-metz fr> wrote:

hi,
i've just update to 0.10 from 0.8.1 and I guess now vala detect one of
my bad.
I used a init function to give my object pointer to external function
that will manage callback :

       init(this)

init() is define in a vapi :
public static void init (ValaObj obj);

and use in External library like this :

static void *ValaObj;
void init (void *obj) {
       ValaObj = obj;
}

Then i define in vapi the callback, C -> Vala :
public delegate uint32 callback ( ValaObj, int value);

and this is my callback in Vala code:
public uint32 cb (ValaObj obj, int value) {
               this = obj;
...
}
it works fine with 0.8.1 and throw exception with 0.10 :
error: unsupported lvalue in assignment
May someone could help me,
thanks in advance,
Cyrille.




_______________________________________________
vala-list mailing list
vala-list gnome org
http://mail.gnome.org/mailman/listinfo/vala-list



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]