]> gitweb.factorcode.org Git - factor.git/blob - basis/glib/ffi/ffi.factor
use radix literals
[factor.git] / basis / glib / ffi / ffi.factor
1 ! Copyright (C) 2010 Anton Gorenko.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors alien alien.destructors alien.libraries
4 alien.strings alien.syntax combinators gobject-introspection
5 gobject-introspection.standard-types io.encodings.utf8 kernel
6 system ;
7 IN: glib.ffi
8
9 LIBRARY: glib
10
11 <<
12 "glib" {
13     { [ os windows? ] [ "libglib-2.0-0.dll" cdecl add-library ] }
14     { [ os macosx? ] [ "/opt/local/lib/libglib-2.0.0.dylib" cdecl add-library ] }
15     { [ os unix? ] [ drop ] }
16 } cond
17 >>
18
19 IMPLEMENT-STRUCTS: GError GPollFD GSource GSourceFuncs ;
20
21 CONSTANT: G_MININT8   -0x80
22 CONSTANT: G_MAXINT8   0x7f
23 CONSTANT: G_MAXUINT8  0xff
24 CONSTANT: G_MININT16  -0x8000
25 CONSTANT: G_MAXINT16  0x7fff
26 CONSTANT: G_MAXUINT16 0xffff
27 CONSTANT: G_MININT32  -0x80000000
28 CONSTANT: G_MAXINT32  0x7fffffff
29 CONSTANT: G_MAXUINT32 0xffffffff
30 CONSTANT: G_MININT64  -0x8000000000000000
31 CONSTANT: G_MAXINT64  0x7fffffffffffffff
32 CONSTANT: G_MAXUINT64 0xffffffffffffffff
33
34 GIR: vocab:glib/GLib-2.0.gir
35
36 DESTRUCTOR: g_source_unref
37 DESTRUCTOR: g_free
38
39 CALLBACK: gboolean GSourceFuncsPrepareFunc ( GSource* source, gint* timeout_ ) ;
40 CALLBACK: gboolean GSourceFuncsCheckFunc ( GSource* source ) ;
41 CALLBACK: gboolean GSourceFuncsDispatchFunc ( GSource* source, GSourceFunc callback, gpointer user_data ) ;
42
43 ERROR: g-error domain code message ;
44
45 : GError>g-error ( GError -- g-error )
46     [ domain>> g_quark_to_string utf8 alien>string ]
47     [ code>> ]
48     [ message>> utf8 alien>string ] tri
49     \ g-error boa ;
50
51 : handle-GError ( GError/f -- )
52     [
53         [ GError>g-error ]
54         [ g_error_free ] bi
55         throw
56     ] when* ;