Fom what I can tell from the documentation I thought it was init
. Although I'm not sure why you would want to use it. It might be useful for some lazy loading of static data used in all instances of the class, but I've never done that myself.
In object oriented programming terminology a class is "instantiated" when it is created as an object. The process of instantiation can be customized with a "constructor". In Vala and Genie it is also possible to customize the process when an object is no longer needed with a "destructor".
If a method does not act upon the data in the object it is called a static
method. By definition a constructor does not act upon the data in the object, but returns a new object. So constructors are always static and static construct
is the wrong name. In Vala there is class construct
and if you change your code to use that you get the same result. See Vala different type of constructors for a thorough treatment on this subject in Vala. The part about class construct
is at the end.
My understanding was Genie's init
was the equivalent of Vala's class construct
. I think your question has uncovered a problem in Genie. My understanding was this code would answer your question:
[indent = 4]
init
var a = new One()
var b = new One()
var c = new One.alternative_constructor()
class One:Object
init
print "Class 'One' is registered with GType"
construct()
print "Object of type 'One' created"
construct alternative_constructor()
print """Obect of type 'One' created with named constructor
'alternative_constructor', but the design of your
class is probably too complex if it has multiple
constructors."""
def One()
print "This is not a constructor"
final
print "Object of type 'One' destroyed"
This, however, outputs:
Class 'One' is registered with GType
Object of type 'One' created
Class 'One' is registered with GType
Object of type 'One' created
Class 'One' is registered with GType
Obect of type 'One' created with named constructor
'alternative_constructor', but the design of your
class is probably too complex if it has multiple
constructors.
Object of type 'One' destroyed
Object of type 'One' destroyed
Object of type 'One' destroyed
Whereas the registration with GType only happens once so the init
code is being put in the wrong place and getting called with each instantiation not with the type registration. So at present I don't think there is an equivalent of Vala's class construct
in Genie.
Changing the behaviour of init
may be one solution, but I may have misunderstood its original purpose and there is probably plenty of code out there now that relies on its current behaviour. The other solution is to write a patch for the Genie parser that implements this. You would need to make a good case why this functionality is useful.