]> gitweb.factorcode.org Git - factor.git/blobdiff - basis/glib/ffi/ffi.factor
Merge branch 'gtk' into gtk-image-loader
[factor.git] / basis / glib / ffi / ffi.factor
index f810348aa0685cc734e2b67a7c19bda4e1cb6f27..22b40f47adbecb8377ab0784b2bb8c623cbcb5a8 100644 (file)
@@ -1,8 +1,9 @@
 ! Copyright (C) 2009 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
-gobject-introspection kernel system vocabs.parser words ;
+alien.libraries alien.strings alien.syntax combinators
+gobject-introspection io.encodings.utf8 kernel system
+vocabs.parser words ;
 IN: glib.ffi
 
 <<
@@ -67,7 +68,7 @@ TYPEDEF: gpointer pointer
 REPLACE-C-TYPE: long\sdouble double
 REPLACE-C-TYPE: any gpointer
 
-IMPLEMENT-STRUCTS: GPollFD GSource GSourceFuncs ;
+IMPLEMENT-STRUCTS: GError GPollFD GSource GSourceFuncs ;
 
 GIR: vocab:glib/GLib-2.0.gir
 
@@ -78,3 +79,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* ;