[Vala] Vapi for time/localtime
- From: "Andreas Sliwka" <andreas sliwka gmail com>
- To: vala-list gnome org
- Subject: [Vala] Vapi for time/localtime
- Date: Fri, 8 Feb 2008 11:05:40 +0100
Greetings,
yesterday I wanted to get the current time from time() and
localtime, found that there is no vapi file for it (at least not on my
ubuntu 0.1.6 packages), and so I tried to make my own.
[CCode (cprefix = "", lower_case_cprefix = "",cheader_filename="time.h")]
namespace Time {
[CCode (cname="struct tm", cprefix="")]
public class TimeStruct {
[CCode (cname="tm_sec")] public int second;
[CCode (cname="tm_min")] public int minute;
[CCode (cname="tm_hour")] public int hour;
[CCode (cname="tm_mday")] public int day_of_month;
[CCode (cname="tm_mon")] public int month;
[CCode (cname="tm_year")] public int year;
[CCode (cname="tm_wday")] public int day_of_week;
[CCode (cname="tm_yday")] public int day_of_year;
[CCode (cname="tm_isdst")] public bool daylight_saving_time;
}
[CCode (cheader_filename = "time.h")]
public static int time (pointer int_ref);
public static weak TimeStruct localtime(ref int time);
}
I somehow suceeded, I can call the functions, but I am not totally
satisfied with what I got so far.
For one thing, the return type of the time() is not int, but (at
loeast on ubuntu) a long long, which would be a gint64 in
<glib/gtypes.h>. but as far as I can see I can not specify this type
in vala - or am I overlooking something?
Secondly the documentation of the GNU localtime says that the returned
pointer to the struct will always point to the same struct, so one
should not keep the reference around and expect the structs content to
stay the same. As a remedy time.h defined the *_r methods which are
thread safe and write the data into a struct, but the user has to
manage the struct herself, mallocing and freeing it as necessary. Now,
how would I write that in a vapi file?
BTW, I started to write the 97th AnalogClock widget (my personal
hello-world in any new language), and I really am astonished about how
easy it is in vala. even while the language feels somehow unfinished,
and the compiler messages are not always helpful and so on, it is fun.
Plain simple fun. The compiler is fast, the turnaround is quick, I
sometimes wondered if valas compile && execute is just as fast as
python's I-have-to-load-4-Mb-of-this-and-that-code-before-I-handle-yours,
the code is clean, bla bla, I think I'm getting carried away.
Best regards,
mfg
Best regards,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]