[Vala] Constructors from odd libs (was: Re: canberra.vapi)



On Sat, 11 Jul 2009, Frederik wrote:

Michael B. Trausch wrote:
On Sat, 11 Jul 2009, Michael 'Mickey' Lauer wrote:

Thanks, that's slightly better, still I'd love to have a classical
constructor
way of creating a context, like:

var c = new Canberra.Context();

Is this impossible without changes in the library itself?


You can (with a bit of work) create APIs that are more object-oriented.
You have to do a bit of extra work, though, and the function has to
return a pointer to a structure (at least, AFAIK).

In this case the problem is that the function returns the newly
constructed object as 'out' parameter, not as return value. AFAIK there
is no 'CCode' attribute for telling Vala to treat an 'out' parameter as
return value.

Hrm. That is interesting. You could write a small C helper that can be layered on top of the library's API and help make things fit. I'm not sure if you can, say, call the "real" constructor in a private static function and invoke that from Vala code in the constructor for the Compact class, but it might be possible.

Another possibility is that there may be some way to tell Vala that the out parameter is the newly-created object -- I don't know of a way to do that, though, at present. It is entirely possible that Jürg or someone else will know, though; I've updated the subject line to better describe the conversation and maybe someone will see it and think of something. If it isn't possible at all at present, maybe filing a feature request asking for an attribute to make the mapping work would be best.

        --- Mike


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