[Vala] self-less delegates



Hi,

I've been exploring Vala lately.  I'm trying to bind to a C library
and implement a class structure on top of a sort of object-oriented C
program that does not use gobject.  Of course I don't mind *my* code
linking to glib, or I wouldn't be looking at Vala.

In any case, in trying to learn the ins and outs of vapi, I ran into a
problem with delegates.  The C library in question uses a registration
function,

class_new(char* name, void* (*)(void) new_method);

So, you register your class and register your new_method function for
that class as a callback.  The library then instantiates your class
whenever it wants.

Anyways, The new_method function does not take any parameters.
However, in trying to use "delegate" to create this callback, I found
that it always seems to add an argument, gpointer *self.  This makes
some sense for most callbacks, but in this case the callback does not
take any parameters.

Additionally, in the translated C it seems to add an argument to
class_new(), so that if my vala says:

Class.new("test", my_new_method);

Then the translated C looks like this:

class_new("test", _extra_stuff_my_new_method, NULL);

So, firstly, it (wrongly, in my case) creates a stub function which
takes a "self" argument, and then adds an extra parameter for this
"self" argument which doesn't exist in the class_new() function.

In my vapi file, I'm prototyping the delegate inside the namespace
scope, but *outside* any class scope.  I think the correct behaviour
here, since it is outside class scope, would be for it not to append
this "self" parameter.

Any thoughts, or ideas on how I could achieve calling class_new() correctly?

thanks,
Steve



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