Re: [Vala] Purple.CoreUiOps

2012-02-19 Thread Joseph Montanez
I got around it. I had to edit the purple.vapi and change it from a
class to struct. However moving along I had to change more classes to
structs. And now I am stuck with callbacks. I am not strong enough
with VAPI's to even know what they heck I am even doing...

Example, I see:
[CCode (cheader_filename = "purple.h")]
[Compact]
public class EventLoopUiOps {
public weak GLib.Callback input_add;
public weak GLib.Callback input_get_error;
public weak GLib.Callback input_remove;
public weak GLib.Callback timeout_add;
public weak GLib.Callback timeout_add_seconds;
public weak GLib.Callback timeout_remove;
}

and changed it too:
[CCode (cheader_filename = "purple.h")]
[Compact]
public struct EventLoopUiOps {
public weak GLib.Callback input_add;
public weak GLib.Callback input_get_error;
public weak GLib.Callback input_remove;
public weak GLib.Callback timeout_add;
public weak GLib.Callback timeout_add_seconds;
public weak GLib.Callback timeout_remove;
}

Then I see:
[CCode (cheader_filename = "purple.h")]
public static uint input_add (int fd, Purple.InputCondition cond,
Purple.InputFunction func);

Now when I try to set input_add:
uint my_input_add(int fd, Purple.InputCondition condition,
Purple.InputFunction func)

Purple.EventLoopUiOps glib_eventloops = Purple.EventLoopUiOps() {
input_add = my_input_add,
input_remove = GLib.Source.remove,
input_get_error = null,
timeout_add = GLib.Timeout.add,
timeout_add_seconds = GLib.Timeout.add_seconds,
timeout_remove = GLib.Source.remove
};

I get "Invalid type for member `input_add'". I am going to take a wild
guess and say that in purple.vapi I need to add some [something that
fixed this] to let me add parameters to a callback?

On Fri, Feb 17, 2012 at 9:08 AM, Joseph Montanez
 wrote:
> I tried that one too:
>
>    Purple.CoreUiOps ui_ops = {
>        null, null, null, null, null
>    };
>
> error: initializer list used for `Purple.CoreUiOps?', which is neither
> array nor struct
>    Purple.CoreUiOps ui_ops = {
>
> And this one:
>
>    var ui_ops = Purple.CoreUiOps() {
>        debug_ui_init = null,
>        get_ui_info = null,
>        quit = null,
>        ui_init = null,
>        ui_prefs_init = null
>    };
>
>    error: syntax error, use `new' to create new objects
>
>
> I took a look at the libpurple headers and it is a struct:
> typedef struct
> {
>     void (*ui_prefs_init)(void);
>     void (*debug_ui_init)(void);
>     void (*ui_init)(void);
>     void (*quit)(void);
>
>     GHashTable* (*get_ui_info)(void);
>
>     void (*_purple_reserved1)(void);
>     void (*_purple_reserved2)(void);
>     void (*_purple_reserved3)(void);
> } PurpleCoreUiOps;
>
> Maybe the libpurple vapi that is bundled with vala is wrong?
>
> On Fri, Feb 17, 2012 at 7:16 AM, Luca Bruno  wrote:
>> On Fri, Feb 17, 2012 at 3:38 PM, Joseph Montanez 
>> wrote:
>>>
>>> My brain is melting trying to figure out how to get Purple.CoreUiOps
>>> to initialize.
>>>
>>> Here is the vapi:
>>>        [CCode (cheader_filename = "purple.h")]
>>>        [Compact]
>>>        public class CoreUiOps {
>>>                [CCode (has_construct_function = false)]
>>>                public weak GLib.Callback debug_ui_init;
>>>                public weak GLib.Callback get_ui_info;
>>>                public weak GLib.Callback quit;
>>>                public weak GLib.Callback ui_init;
>>>                public weak GLib.Callback ui_prefs_init;
>>>        }
>>
>>
>> Try with a struct.
>>
>> --
>> www.debian.org - The Universal Operating System
>
>
>
> --
> Joseph Montanez
> Web Developer
> Gorilla3D
> Design, Develop, Deploy



-- 
Joseph Montanez
Web Developer
Gorilla3D
Design, Develop, Deploy
___
vala-list mailing list
vala-list@gnome.org
http://mail.gnome.org/mailman/listinfo/vala-list


Re: [Vala] Safe call operator

2012-02-19 Thread pancake
i really like the idea of having the elvis operator and the safe navigation 
operator in Vala.

fmi : http://groovy.codehaus.org/Operators

is this going to be added at some point into the compiler?

On Feb 1, 2012, at 21:08, Jim Nelson  wrote:

> I was going to mention that as well.  Null handling in Java is not
> analogous to Vala's strategy, if for no other reason than there's no NPE.
> 
> It looks to me the idea of a future Vala that emphasizes code correctness
> is that it will catch things like this:
> 
> Xyxxy? x = get_xyzzy();
> int result = x.foo();
> 
> The compiler will flag that last line as problematic.  I think it will, at
> least.  I don't really know.  But it seems to me that if null-checking is
> going to be enforced by the compiler, it's not too much to ask the language
> to supply good tools for doing that checking.  The nullable operator is one
> step in that direction, but I've coded many lines where I needed something
> like the Elvis operator (and the associated operators suggested by Project
> Coin).
> 
> I'll also point out that (according to the Project Coin page) the reason
> the null-safety operators were turned down by the Java committee was that
> the Checker framework was added to Java and that Groovy, the inspiration
> for the proposed syntax, uses dynamic typing, which makes the operators
> more flexible.  But the first is not going to happen for Vala (I've not
> heard of any such framework) and the second could be made to argue against
> the nullable operator, which was, in fact, added to Vala.
> 
> I think the Elvis operator (and its cousins) should get real consideration
> and not be dismissed merely because Java didn't take them.
> 
> -- Jim
> 
> 
> 
> On Tue, Jan 31, 2012 at 7:27 AM, Artem Tarasov 
> wrote:
> 
>>> As a starter, Java rejected that syntax.
>> 
>> Yeah, but in Java at least a NullPointerException is thrown when null
>> dereferencing occurs. In Vala the only option to provide null-safety
>> is explicit checking for null after each method call in a chain.
>> ___
>> vala-list mailing list
>> vala-list@gnome.org
>> http://mail.gnome.org/mailman/listinfo/vala-list
>> 
> ___
> vala-list mailing list
> vala-list@gnome.org
> http://mail.gnome.org/mailman/listinfo/vala-list
___
vala-list mailing list
vala-list@gnome.org
http://mail.gnome.org/mailman/listinfo/vala-list


Re: [Vala] Sample app built with ninja+vala

2012-02-19 Thread Tal Hadad

You mention Tup, which I see this as a great tool.
But have anyone found an autoconf alternative for Tup?

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


Re: [Vala] Create an instance of a derived class, from a base class method

2012-02-19 Thread Tal Hadad

It's not for you at all(and won't solve anything), but take a look at this 
example:
https://live.gnome.org/Vala/GStreamerSample

> Date: Sun, 19 Feb 2012 13:24:31 +
> Subject: Re: [Vala] Create an instance of a derived class, from a base class 
> method
> From: blowb...@gmail.com
> To: tal...@hotmail.com
> CC: vala-list@gnome.org
> 
> 2012/2/19 Tal Hadad :
> >
> > I don't understand what is your purpose:
> > I don't understand why you don't use constructors, or static methods.
> 
> I'd got myself in a bit of a mess inheriting singleton factory classes
> and static properties/methodscoming from a C background, I get a
> bit over-exciteable around OO. I've since refactored with templates
> and accepted the 'singletons are evil' lore, which has made everything
> a lot simpler.
> 
> > See, the type deceleration must be explicit at complication time.
> > However, if you don't want it, you can always use generics and the 
> > "dynamic" word.
> 
> Meh, I very much like the concept of 'complication time'. What is this
> 'dynamic' keyword of which you speak?
> 
> cheers
> ant
  ___
vala-list mailing list
vala-list@gnome.org
http://mail.gnome.org/mailman/listinfo/vala-list


Re: [Vala] Create an instance of a derived class, from a base class method

2012-02-19 Thread ant
2012/2/19 Tal Hadad :
>
> I don't understand what is your purpose:
> I don't understand why you don't use constructors, or static methods.

I'd got myself in a bit of a mess inheriting singleton factory classes
and static properties/methodscoming from a C background, I get a
bit over-exciteable around OO. I've since refactored with templates
and accepted the 'singletons are evil' lore, which has made everything
a lot simpler.

> See, the type deceleration must be explicit at complication time.
> However, if you don't want it, you can always use generics and the "dynamic" 
> word.

Meh, I very much like the concept of 'complication time'. What is this
'dynamic' keyword of which you speak?

cheers
ant
___
vala-list mailing list
vala-list@gnome.org
http://mail.gnome.org/mailman/listinfo/vala-list


Re: [Vala] Create an instance of a derived class, from a base class method

2012-02-19 Thread Tal Hadad

I don't understand what is your purpose:
I don't understand why you don't use constructors, or static methods.

See, the type deceleration must be explicit at complication time.
However, if you don't want it, you can always use generics and the "dynamic" 
word.

In simple words, as far as I know, what you want to achieve isn't possible(but 
could be manually implicated).

Yours,
Tal

> Date: Sat, 18 Feb 2012 15:51:55 +
> From: blowb...@gmail.com
> To: vala-list@gnome.org
> Subject: [Vala] Create an instance of a derived class,from a base 
> class method
> 
> Hi,
> 
> I am trying to craft a base class method, that is able to create an
> object of the same class as whatever derived-class object it was
> called on.
> 
> For example, if classes Bar and Baz both derive from Foo, and Foo has
> a create() method, then bar.create() should give me an instance of
> Bar, and Baz.create() should give me an instance of Baz.
> 
> I've spent so long happily experimenting with this that I forgot the
> original requirement. but I have come up with two approaches that
> almost work (below).
> 
> Everything is fine at run-time, but I have to resort to ugly casts
> like "Derived obj = derived.foo() as Derived" to get valac to accept
> it.
> 
> I think the return type ('Base') of foo() is my problem, but I'm at a
> loss as to what to replace it with to make this work.
> 
> Is there a better way to achieve this sort of thing?
> 
> 
> 
> 
> public class Base : GLib.Object {
> public Base foo() {
> Type t = this.get_type();
> return Object.new(t) as Base;
> }
> }
> 
> public class Derived : Base {
> public void test() {
> stdout.printf("I am an instance of Derived!\n");
> }
> }
> 
> //
> 
> /* second attempt with abstract methods */
> public abstract class Base2 : GLib.Object {
> public Base2 foo() {
> return new_instance();
> }
> protected abstract Base2 new_instance();
> 
> }
> 
> public class Derived2 : Base2 {
> 
> /* return type has to be Base2 or vala won't allow the override */
> public override Base2 new_instance() {
> return new Derived2();
> }
> 
> public void test() {
> stdout.printf("Derived2: I am an instance of Derived2!\n");
> }
> }
> 
> 
> //
> 
> 
> public static int main(string[] args) {
> 
> #if false
> Derived derived = new Derived();
> Derived obj = derived.foo(); // 'cannot convert from Base to Derived?'
> #else
> Derived derived = new Derived();
> Derived obj = derived.foo() as Derived; // ugly!
> #endif
> 
> Type t = obj.get_type();
> stdout.printf("Type of obj is %s\n", t.name());
> obj.test();
> 
> 
> /* second attempt with abstract methods */
> #if false
> Derived2 derived2 = new Derived2();
> Derived2 obj2 = derived2.foo(); // 'cannot convert from Base to Derived?'
> #else
> Derived2 derived2 = new Derived2();
> Derived2 obj2 = derived2.foo() as Derived2; // ugly!
> #endif
> 
> Type t2 = obj2.get_type();
> stdout.printf("Type of obj2 is %s\n", t2.name());
> obj2.test();
> 
> 
> return 0;
> }
> 
> 
> cheers
> ant
> ___
> vala-list mailing list
> vala-list@gnome.org
> http://mail.gnome.org/mailman/listinfo/vala-list
  ___
vala-list mailing list
vala-list@gnome.org
http://mail.gnome.org/mailman/listinfo/vala-list


Re: [Vala] How do you get from the generic, to the.....specific?

2012-02-19 Thread Luca Bruno
On Sun, Feb 19, 2012 at 5:32 AM, Matto Marjanovic  wrote:

> Are there any plans to add type bounds to Vala generics?
>
> This would allow something like (e.g., using Java's keyword):
>
> public int get_length  (T val) {
>  return val.length;
> }
>
>
Yes, but not anytime soon.

-- 
www.debian.org - The Universal Operating System
___
vala-list mailing list
vala-list@gnome.org
http://mail.gnome.org/mailman/listinfo/vala-list