Thanks for the fast reply.

On Fri, Mar 26, 2010 at 6:45 PM, Julian Andres Klode <j...@jak-linux.org> wrote:
> On Fri, Mar 26, 2010 at 11:07:20AM +0800, PCMan wrote:
>> Hi list,
>> I tried to use Vala for the first time and the following code failed
>> to generate correct C code.
>> Is this a bug of vala or what's wrong with my code? (code is attached
>> to the end of this mail)
> You define *_finish which is already defined by making the standard
> functions async. Read
>        http://live.gnome.org/Vala/Tutorial#Asynchronous_Functions
>
> But Vala should probably report an error if one creates an async
> function "f" and a function "f_finish"; instead of creating invalid
> code.
The problem is, if I only override f, vala complains about abstract
method f_finish is not implemented. If I override f_finish, too, then
this results in duplicated method definition since another one is
automatically generated by vala async mechanism. So, it's not possible
to implement a interface like GVolume in vala. If this is not the
desired behavior, then it should be a bug. If this can be done in
vala, that can be quite useful. I'm trying to imiplement a new
GVolumeMonitor for gio based on some dbus services. Since vala has
amazing dbus support, it's the best tool I can think of for this job.
It's a pity that I encountered this error.

For the second question, if I want to return a unowned GList, it has
to be owned by the class and cannot be a local variable, right? Would
you please add this to vala tutorial? I found it not documented and
this behavior is not easy to figure out. In addition, this is not
consistent with GObject with C. In C we can create a new GList and
return it without the need to make it owned by anyone. The callee of
the function is responsible to free the list. So I expect the same
behavior in vala. IMHO if thing like this is possible, it will be
useful and be more consistent with C, hence making transition from C
easier.

For example, IMO this should be supported.
public unowned GLib.List<GLib.Object> get_list() {
    var list = new GLib.List<GLib.Object>();
   // Do something to append items to the list
    return list; // transfer the ownership to callee
}

public void yet_another_function() {
    // retrive the list and get ownership
    var GLib.List<GLib.Object> returned_list = owned get_list();
}  // returned_list is freed here.

BTW, congratulations for vala. It's really amazing and greatly
decrease development time!

>>
>> In addition, if I want to override a virtual function in a parent
>> class with the prototype like this:
>> public virtual unowned GLib.List get_volumes ();
>>
>> How can I return an unowned GLib.List in my override function? I tried
>> and tried but nothing works.
>
> Something like this should work:
>        public override unowned GLib.List get_volumes() {
>                return list;
>        }
> You of course need a reference to the list somewhere in your
> class.
>
> --
> 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