]> gitweb.factorcode.org Git - factor.git/blobdiff - basis/glib/ffi/ffi.factor
use radix literals
[factor.git] / basis / glib / ffi / ffi.factor
index 99183a88dc7ada495357e3a68eadc4ad5766be70..96d92663eb8d6fa3f78eea35c8df1f4fcdbdf325 100644 (file)
@@ -1,73 +1,35 @@
-! Copyright (C) 2009 Anton Gorenko.
+! Copyright (C) 2010 Anton Gorenko.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: accessors alien alien.c-types alien.destructors
-alien.libraries alien.syntax combinators compiler.units gir
-kernel system vocabs.parser words ;
+USING: accessors alien alien.destructors alien.libraries
+alien.strings alien.syntax combinators gobject-introspection
+gobject-introspection.standard-types io.encodings.utf8 kernel
+system ;
 IN: glib.ffi
 
+LIBRARY: glib
+
 <<
 "glib" {
-    { [ os winnt? ] [ "libglib-2.0-0.dll" cdecl add-library ] }
+    { [ os windows? ] [ "libglib-2.0-0.dll" cdecl add-library ] }
     { [ os macosx? ] [ "/opt/local/lib/libglib-2.0.0.dylib" cdecl add-library ] }
-    { [ os unix? ] [ "libglib-2.0.so" cdecl add-library ] }
+    { [ os unix? ] [ drop ] }
 } cond
 >>
 
-<< double "long double" current-vocab create typedef >>
-
-TYPEDEF: char gchar
-TYPEDEF: uchar guchar
-TYPEDEF: short gshort
-TYPEDEF: ushort gushort
-TYPEDEF: long glong
-TYPEDEF: ulong gulong
-TYPEDEF: int gint
-TYPEDEF: uint guint
-
-<<
-int c-type clone
-    [ >c-bool ] >>unboxer-quot
-    [ c-bool> ] >>boxer-quot
-    object >>boxed-class
-"gboolean" current-vocab create typedef
->>
-
-TYPEDEF: char gint8
-TYPEDEF: uchar guint8
-TYPEDEF: short gint16
-TYPEDEF: ushort guint16
-TYPEDEF: int gint32
-TYPEDEF: uint guint32
-TYPEDEF: longlong gint64
-TYPEDEF: ulonglong guint64
-
-TYPEDEF: float gfloat
-TYPEDEF: double gdouble
-
-TYPEDEF: long ssize_t
-TYPEDEF: long time_t
-TYPEDEF: size_t gsize
-TYPEDEF: ssize_t gssize
-TYPEDEF: size_t GType
-
-TYPEDEF: void* gpointer
-TYPEDEF: void* gconstpointer
-
-TYPEDEF: guint8 GDateDay
-TYPEDEF: guint16 GDateYear
-TYPEDEF: gint GPid
-TYPEDEF: guint32 GQuark
-TYPEDEF: gint32 GTime
-TYPEDEF: glong gintptr
-TYPEDEF: gint64 goffset
-TYPEDEF: gulong guintptr
-TYPEDEF: guint32 gunichar
-TYPEDEF: guint16 gunichar2
-
-TYPEDEF: gpointer pointer
-TYPEDEF: gpointer any
-
-IMPLEMENT-STRUCTS: GPollFD GSource GSourceFuncs ;
+IMPLEMENT-STRUCTS: GError GPollFD GSource GSourceFuncs ;
+
+CONSTANT: G_MININT8   -0x80
+CONSTANT: G_MAXINT8   0x7f
+CONSTANT: G_MAXUINT8  0xff
+CONSTANT: G_MININT16  -0x8000
+CONSTANT: G_MAXINT16  0x7fff
+CONSTANT: G_MAXUINT16 0xffff
+CONSTANT: G_MININT32  -0x80000000
+CONSTANT: G_MAXINT32  0x7fffffff
+CONSTANT: G_MAXUINT32 0xffffffff
+CONSTANT: G_MININT64  -0x8000000000000000
+CONSTANT: G_MAXINT64  0x7fffffffffffffff
+CONSTANT: G_MAXUINT64 0xffffffffffffffff
 
 GIR: vocab:glib/GLib-2.0.gir
 
@@ -78,3 +40,17 @@ CALLBACK: gboolean GSourceFuncsPrepareFunc ( GSource* source, gint* timeout_ ) ;
 CALLBACK: gboolean GSourceFuncsCheckFunc ( GSource* source ) ;
 CALLBACK: gboolean GSourceFuncsDispatchFunc ( GSource* source, GSourceFunc callback, gpointer user_data ) ;
 
+ERROR: g-error domain code message ;
+
+: GError>g-error ( GError -- g-error )
+    [ domain>> g_quark_to_string utf8 alien>string ]
+    [ code>> ]
+    [ message>> utf8 alien>string ] tri
+    \ g-error boa ;
+
+: handle-GError ( GError/f -- )
+    [
+        [ GError>g-error ]
+        [ g_error_free ] bi
+        throw
+    ] when* ;