Hi,

On Mon, 2008-04-21 at 00:08 +0200, Klaus Rotter wrote:
> I have started coding with vala and I really like it! Great work! It is
> really a big step ahead compared to plain C gtk programming.

Thanks.

> But I have some questions:
> 
> 1) I often use some preprocessor strings in my C code like __DATE__
> __TIME__. Is this feature also available in vala?

No, these preprocessor strings are not supported at the moment. You
could use them by declaring them in a .vapi file:

        [CCode (cname = "__DATE__")]
        public const string __DATE__;

> 2) Something more complicated. I want to write a vapi file for the
> tremor integer vorbis lib. As far I understand, I have to make a class
> file of every struct I want to use. But I must only put the interesting
> stuff of the c struct inside the class file, because every class is
> translated to the complete c-struct at compile time.

Vala supports both, classes and structs. The difference is that a class
is assumed to be heap-allocated and to have reference-type semantics. A
struct may be stack-allocated and has value-type semantics. You have to
decide for each C struct whether it better fits a Vala class or struct.

> I have the following c-calls: (OggVorbis_File is the basic typedef'd
> struct)
> 
> extern int ov_clear(OggVorbis_File *vf);
> extern int ov_open(FILE *f,OggVorbis_File *vf,char *initial,longibytes);
> extern long ov_bitrate(OggVorbis_File *vf);
> 
> I want to write a vapi which lets me act like that:
> 
> var ov = new OggVorbisFile();
> ov.open("test.ogg");
> bitrate = ov.get_bitrate();
> 
> and it should be translated to something like that: (Pseudocode)
> 
> ov = g_malloc(sizeof(OggVorbis_File)); 
> FILE f = g_fopen("test.ogg","r"); 
> ov_open(f,ov,NULL,NULL);
> bitrate = ov_bitrate(ov);
> ...
> ov_clear(ov);
> g_free(ov);
> 
> Can vapi does this for me or do I have to write some c stubs or better a
> vala class. How do I enable error handling with try {...} catch if the
> file could not be opened?
> Maybe the best will be that I define a basic class with vapi to access
> the c-lib-calls and put everything else in a derived vala class which
> handels errors and more.

This sounds about right. If you want error handling with try catch and
an API like the above, you need a wrapper library, i.e. a .vapi and one
or more .vala files. OggVorbis_File should be declared as a struct in
the .vapi as it's not heap-allocated by its own.

Jürg

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

Reply via email to