hi fabian,

thanks for you immediate reply. i already had a look at the c-code but i
must admit i dont fully understand it. however, as i said, if i change
the previous sample code this way (NEW LINE) ....

public class MyObject:Object{}

void main () {          
 Type typeFromClassLiteral = typeof(MyObject); // NEW LINE !!!

 Type typeFromName = Type.from_name("MyObject"); 
 print("%s\n", typeFromName.to_string());       
 print("%s\n", typeFromName.name()); 
}

i get something like this ....

161307536
MyObject

... so everything seems to be fine although no instance of MyObject was
created. anyway, you are right: when i look at the c-code now, the new
line above becomes ... 

typeFromClassLiteral = TYPE_MY_OBJECT;

... and although i dont know much about c, it seems to me that
TYPE_MY_OBJECT is defined as ...

my_object_get_type () 

... which is again a function that registers the type internally.

however, is there any chance to do this type registration manually from
vala code? 

ok, i guess, not. anyway. thank you!

peter



Am Mittwoch, den 29.09.2010, 19:07 +0200 schrieb Fabian Deutsch:
> hello.
> 
> > however, if i run the following sample code ...
> > 
> > public class MyObject:Object{}
> > 
> > void main () { 
> >  Type typeFromName = Type.from_name("MyObject"); 
> >  print("%s\n", typeFromName.to_string()); 
> >  print("%s\n", typeFromName.name()); 
> > }
> > 
> > ... i get the following output:
> > 
> > 0
> > (null)
> > 
> > ... which i obviously cannot use to create any object. 
> > 
> > i discovered that the code above works, but only if an object of
> > MyObject was previously created or if i previously used typeof(MyObject)
> > and assigned that type-object to some variable. 
> 
> This is, because types are registered only on the first use and not before. 
> If you compile that code and look at the generated c-code, you see that the 
> type is registered only when creating an instance.
> 
> - fabian

_______________________________________________
vala-list mailing list
[email protected]
http://mail.gnome.org/mailman/listinfo/vala-list

Reply via email to