On Do, 2010-12-09 at 11:35 -0600, W. Michael Petullo wrote:
> I am having trouble with Vala and a GHashTable-style foreach. I have
> created a Vala API for my library, which defines an interface with a
> GHashTable-style foreach method. Vapigen / my Vala API file defines
> this as:
> 
> public abstract void @foreach(GLib.HFunc func, void *data)
> 
> When I define a method in Vala as follows, I end up with an extra argument
> in the generated C source:
> 
> public void @foreach (GLib.HFunc func, void *data) {...}
> 
> generates:
> 
> static void class_real_foreach (DMAPDb* base, GHFunc func,
>                               void* func_target, void* data) {...}
> 
> and fails to compile (note the two "user_data" parameters: func_target
> and data).
That's expected, as Vala handles user data itself, see below.

> 
> When I remove the "void *data" from the Vala code (and Vala API file),
> everything compiles fine. However, the generated C code contains calls
> such as the following:
> 
> dmap_db_foreach ((DMAPDb*) self->priv->db,
>                (GHFunc) dpap_viewer_render_record, NULL);
> 
> So, the parameter passed as "user_data" is NULL. But, I need to pass
> something. What am I doing wrong?
You shouldn't pass user data pointers in Vala, Vala does this automatic
(the current scope for lambda expressions, the object when passing
obj.method, and NULL if you're function takes no user data).

-- 
Julian Andres Klode  - Debian Developer, Ubuntu Member

See http://wiki.debian.org/JulianAndresKlode and http://jak-linux.org/.


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

Reply via email to