Re: [Vala] [Genie] Object members



On Wed, 2009-10-28 at 10:39 +0000, Patrick Castle wrote:
Just stuffing about at the moment getting my head about creating classes in
Genie. From what I gather, every variable you declare outside of a method is a
member/property of that class.

What I'm finding a bit confusing is there isn't just one way to declare a
property it seems - but both ways don't work consistently.

For example, I have class "Test" and I want it to have a private property "a"
not accessible to external callers. It seems like these are the options:

class Test : Object
    _a : int

or

class Test : Object
    prop private a : int

or

class Test : Object
    prop _a : int

but not

class Test : Object
    private a : int



a : private int


My first question - is there any reason why that last one shouldn't compile?
Also - why actually have so many ways to declare the same thing? Is it
deliberate or just an accident of the syntax checking? 

they are not all the same




Also - does Genie have the concept of a class variable, or are they all just
instance variables? My initial temptation was to use static in the declaration

class Test : Object
    prop static a : int

This actually starts spitting out all sorts of errors when compiling the C
source, so perhaps it gets further than it should. Is it an illegal declaration?
And if so, should it be caught before it gets as far as the C source being
created and compiled?

On the Genie homepage it says:
All methods, properties and events can also take modifiers to define further
options.

I assumed that would mean that all modifiers were legal. So I thought I should
try the other modifiers.

abstract:

class Test : Object
    prop abstract a : int

This one compiles OK, but if you create an instance of the class and assign a
value to the property you get a Segmentation Fault when you run it. 

possibly a bug - im not sure if abstract properties are supported


I looked at the definition of abstract and it seems to say that it should not be
defined in the class in which it's declared but only in the subclass. So I
created a subclass and defined it there instead and I still get a clean compile
but a Segmentation Fault when running.

I'm guessing that this is only meant for methods rather than properties - but if
so, it would probably be a good idea to make a distinction on the web page
between method modifiers and property modifiers. Seems like the remaining
modifiers look relevant only to methods as well.

Also - I think rather than getting a Segmentation Fault, improper use of these
modifiers should probably throw exceptions during the compile.
 
So to summarise, declaration of properties implies public access unless keyword
private is used (or underscore). Your options are: _var, prop private var, prop
_var.

if you dont use prop then its a field 


There is no such thing as a class variable in Genie.

not sure what you mean here?


Would that be an accurate summary?

no


Regards
Patrick

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




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