[Vala] Legacy Bindings: "Inject" & operator?



The other day I was using Posix.ctime a lot on various time_t types.
I pondered whether it would be helpful to add a to_string() method to make
this a bit more convenient.

Ideally I would state something like

diff --git a/vapi/glib-2.0.vapi b/vapi/glib-2.0.vapi
index 82785747e..31a68885f 100644
--- a/vapi/glib-2.0.vapi
+++ b/vapi/glib-2.0.vapi
@@ -908,6 +908,8 @@ public struct double {
public struct time_t {
       [CCode (cname = "time")]
       public time_t (out time_t result = null);
+       [CCode (cname = "ctime")]
+       public unowned string to_string();
}

This doesn’t work though, since time_t is bounds as IntegerType, hence the compiler bails out with:

/Volumes/ramdisk/time.c:29:18: warning: incompatible integer to pointer conversion passing 'time_t' (aka 
'long') to parameter of type 'const time_t *'
     (aka 'const long *'); take the address with & [-Wint-conversion]
       _tmp1_ = ctime (now);
                       ^~~
                       &

Independent of whether this patch can make it to glib-2.0.vapi or not, I wonder
whether there is a CCode attribute that could make this happen without introducing
a vala helper method.

Cheers,

Mickey.





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]