Re: [Vala] memory management with structs [Solved]

2013-05-19 Thread Donn

On 18/05/2013 16:46, Jonas Kulla wrote:

i.e. How do you create a class that does*not*  inherit from GObject?
By not specifying a parent class, ie. just "class MyKlass { ... }".

Thanks!

\d
___
vala-list mailing list
vala-list@gnome.org
https://mail.gnome.org/mailman/listinfo/vala-list


Re: [Vala] Vala and Cairo 1.12

2013-05-19 Thread Donn

On 18/05/2013 16:57, Jonas Kulla wrote:

It's basically the same as declaring foreign functions in C.
Let's say you want to use the function 'int cairo_do_foo()' from Vala,
you would write something like:

namespace Cairo {
 [CCode (cname="cairo_do_foo")]
 extern int do_foo();
}

The 'CCode' part is a directive to valac for how it should
output the C code. We tell it the actual C function name
to use.


Noted. Thanks for the help.

\d
___
vala-list mailing list
vala-list@gnome.org
https://mail.gnome.org/mailman/listinfo/vala-list


[Vala] Why do we keep static fields in GObject derived classes?

2013-05-19 Thread Geert Jordaens

Why do we keep static fields in GObject derived classes?

There is currently no way of correctly accessing static class members 
unless at least one object is instantiated.
Moreover the initialisation of the fields depends on the variable type 
(valuetype/reftype).


public class ClassA : Object {
public static int int_value_a = 7;// <= 
Initialised in outside GObject class
public static string string_value_a = "7";  // <= Initialised 
within the GObject class *_class_init

}

void main() {
stdout.printf("Access to static member ClassA.int_value_a == 
%d\n",ClassA.int_value_a);
stdout.printf("Access to static member ClassA.string_value_a == 
%s\n",ClassA.string_value_a);

var a = new ClassA();
stdout.printf("After first ClassA object instatiation\n");
stdout.printf("Access to static member ClassA.int_value_a == 
%d\n",ClassA.int_value_a);
stdout.printf("Access to static member ClassA.string_value_a == 
%s\n",ClassA.string_value_a);

}

=> output

Access to static member ClassA.int_value_a== 7
Access to static member ClassA.string_value_a == (null)
After first ClassA object instatiation
Access to static member ClassA.int_value_a== 7
Access to static member ClassA.string_value_a == 7


Could we define static fields as guaranteed initialized once class 
fields? Keep the static modifier as a guard.


public class ClassA : Object {
public static int int_value_a = 7;// <= 
Move field initializer within the GObject class *_class_init
public static string string_value_a = "7";  // <= Move field 
initializer within the GObject class *_class_init (AS-IS)


/*
 * Allow as field initializers are generated within the GObject 
class *_class_init

 */
static construct {
int_value_a = 7;
string_value_a = "7";
}

/*
 * Not allow access to static fields in a class construct block
 * as field initializers are generated within the GObject class 
*_base_init
 * and are initialized on each first call of a Gobject Type / 
Sub Type

 */
class construct {
/*
 * Issue an Error or Waring for BC:
 * Access to static member %s.%s in class construct 
forbidden/discouradged

 */
int_value_a = 6;
string_value_a = "6";
}

/*
 * Not allow access to static fields in a object construct block
 * as field initializers are generated within the GObject class 
*_constructor

 * and are initialized on each instantiation of an object.
 */
construct {
/*
 * Issue an Error or Waring for BC:
 * Access to static member %s.%s in construct 
forbidden/discouradged

 */
int_value_a = 5;
string_value_a = "5";
}

/*
 *  Not allow access in the standard object constructor 
(guaranteed initialize once)

 */
publicClassA () {
/*
 * Issue an Error or Waring for BC:
 * Access to static member %s.%s in construct 
forbidden/discouradged

 */
int_value_a = 4;
string_value_a = "4";
}

/*
 *  Allow access for a non standard constuctor that overrules 
guaranteed initialize once

 */
publicClassA.x () {
int_value_a = 4;
string_value_a = "4";
}
}


I think this would make the behavior more defined.
___
vala-list mailing list
vala-list@gnome.org
https://mail.gnome.org/mailman/listinfo/vala-list