gir_ffi 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. data/DESIGN.rdoc +9 -0
  2. data/History.txt +11 -0
  3. data/TODO.rdoc +6 -9
  4. data/examples/01_empty_window.rb +1 -1
  5. data/examples/02_hello_world.rb +4 -4
  6. data/examples/03_upgraded_hello_world.rb +7 -8
  7. data/lib/gir_ffi.rb +0 -4
  8. data/lib/gir_ffi/arg_helper.rb +27 -2
  9. data/lib/gir_ffi/builder.rb +13 -86
  10. data/lib/gir_ffi/builder_helper.rb +2 -15
  11. data/lib/gir_ffi/class_base.rb +51 -0
  12. data/lib/gir_ffi/class_builder.rb +178 -52
  13. data/lib/gir_ffi/function_definition_builder.rb +46 -9
  14. data/lib/gir_ffi/g_object.rb +37 -0
  15. data/lib/gir_ffi/i_arg_info.rb +27 -9
  16. data/lib/gir_ffi/i_base_info.rb +12 -4
  17. data/lib/gir_ffi/i_callable_info.rb +15 -5
  18. data/lib/gir_ffi/i_enum_info.rb +9 -3
  19. data/lib/gir_ffi/i_field_info.rb +12 -4
  20. data/lib/gir_ffi/i_function_info.rb +24 -8
  21. data/lib/gir_ffi/i_object_info.rb +63 -21
  22. data/lib/gir_ffi/i_registered_type_info.rb +11 -0
  23. data/lib/gir_ffi/i_repository.rb +2 -2
  24. data/lib/gir_ffi/i_signal_info.rb +1 -1
  25. data/lib/gir_ffi/i_struct_info.rb +24 -8
  26. data/lib/gir_ffi/i_type_info.rb +24 -8
  27. data/lib/gir_ffi/i_union_info.rb +15 -0
  28. data/lib/gir_ffi/i_value_info.rb +3 -1
  29. data/lib/gir_ffi/i_vfunc_info.rb +12 -1
  30. data/lib/gir_ffi/lib.rb +23 -1
  31. data/lib/gir_ffi/lib_c.rb +1 -1
  32. data/lib/gir_ffi/module_base.rb +19 -0
  33. data/lib/gir_ffi/module_builder.rb +67 -20
  34. data/lib/gir_ffi/overrides/gobject.rb +174 -0
  35. data/lib/gir_ffi/overrides/gtk.rb +26 -9
  36. data/test/builder_test.rb +57 -37
  37. data/test/{base_test.rb → class_base_test.rb} +3 -3
  38. data/test/class_builder_test.rb +48 -6
  39. data/test/everything_test.rb +285 -36
  40. data/test/function_definition_builder_test.rb +11 -9
  41. data/test/g_object_test.rb +22 -0
  42. data/test/gobject_overrides_test.rb +216 -0
  43. data/test/i_object_info_test.rb +21 -0
  44. data/test/module_builder_test.rb +54 -0
  45. data/test/test_helper.rb +6 -4
  46. metadata +18 -14
  47. data/lib/gir_ffi/base.rb +0 -25
  48. data/lib/gir_ffi/constructor_definition_builder.rb +0 -20
  49. data/lib/gir_ffi/g_type.rb +0 -14
  50. data/lib/gir_ffi/method_missing_definition_builder.rb +0 -59
  51. data/test/constructor_definition_builder_test.rb +0 -19
  52. data/test/g_type_test.rb +0 -22
@@ -32,10 +32,18 @@ module GirFFI
32
32
 
33
33
  private_class_method :new
34
34
 
35
- def name; Lib.g_base_info_get_name @gobj; end
36
- def type; Lib.g_base_info_get_type @gobj; end
37
- def namespace; Lib.g_base_info_get_namespace @gobj; end
38
- def deprecated?; Lib.g_base_info_is_deprecated @gobj; end
35
+ def name
36
+ Lib.g_base_info_get_name @gobj
37
+ end
38
+ def type
39
+ Lib.g_base_info_get_type @gobj
40
+ end
41
+ def namespace
42
+ Lib.g_base_info_get_namespace @gobj
43
+ end
44
+ def deprecated?
45
+ Lib.g_base_info_is_deprecated @gobj
46
+ end
39
47
 
40
48
  def self.wrap ptr
41
49
  return nil if ptr.null?
@@ -6,11 +6,21 @@ module GirFFI
6
6
  # Wraps a GICallableInfo struct; represents a callable, either
7
7
  # IFunctionInfo, ICallbackInfo or IVFuncInfo.
8
8
  class ICallableInfo < IBaseInfo
9
- def return_type; ITypeInfo.wrap(Lib.g_callable_info_get_return_type @gobj); end
10
- def caller_owns; Lib.g_callable_info_get_caller_owns @gobj; end
11
- def may_return_null?; Lib.g_callable_info_may_return_null @gobj; end
12
- def n_args; Lib.g_callable_info_get_n_args @gobj; end
13
- def arg(index); IArgInfo.wrap(Lib.g_callable_info_get_arg @gobj, index); end
9
+ def return_type
10
+ ITypeInfo.wrap(Lib.g_callable_info_get_return_type @gobj)
11
+ end
12
+ def caller_owns
13
+ Lib.g_callable_info_get_caller_owns @gobj
14
+ end
15
+ def may_return_null?
16
+ Lib.g_callable_info_may_return_null @gobj
17
+ end
18
+ def n_args
19
+ Lib.g_callable_info_get_n_args @gobj
20
+ end
21
+ def arg(index)
22
+ IArgInfo.wrap(Lib.g_callable_info_get_arg @gobj, index)
23
+ end
14
24
  ##
15
25
  build_array_method :args
16
26
  end
@@ -2,12 +2,18 @@ module GirFFI
2
2
  # Wraps a GIEnumInfo struct if it represents an enum.
3
3
  # If it represents a flag, an IFlagsInfo object is used instead.
4
4
  class IEnumInfo < IRegisteredTypeInfo
5
- def n_values; Lib.g_enum_info_get_n_values @gobj; end
6
- def value(index); IValueInfo.wrap(Lib.g_enum_info_get_value @gobj, index); end
5
+ def n_values
6
+ Lib.g_enum_info_get_n_values @gobj
7
+ end
8
+ def value(index)
9
+ IValueInfo.wrap(Lib.g_enum_info_get_value @gobj, index)
10
+ end
7
11
  ##
8
12
  build_array_method :values
9
13
 
10
- def storage_type; Lib.g_enum_info_get_storage_type @gobj; end
14
+ def storage_type
15
+ Lib.g_enum_info_get_storage_type @gobj
16
+ end
11
17
  end
12
18
  end
13
19
 
@@ -2,9 +2,17 @@ module GirFFI
2
2
  # Wraps a GIFieldInfo struct.
3
3
  # Represents a field of an IStructInfo or an IUnionInfo.
4
4
  class IFieldInfo < IBaseInfo
5
- def flags; Lib.g_field_info_get_flags @gobj; end
6
- def size; Lib.g_field_info_get_size @gobj; end
7
- def offset; Lib.g_field_info_get_offset @gobj; end
8
- def type; ITypeInfo.wrap(Lib.g_field_info_get_type @gobj); end
5
+ def flags
6
+ Lib.g_field_info_get_flags @gobj
7
+ end
8
+ def size
9
+ Lib.g_field_info_get_size @gobj
10
+ end
11
+ def offset
12
+ Lib.g_field_info_get_offset @gobj
13
+ end
14
+ def type
15
+ ITypeInfo.wrap(Lib.g_field_info_get_type @gobj)
16
+ end
9
17
  end
10
18
  end
@@ -2,15 +2,31 @@ module GirFFI
2
2
  # Wraps a GIFunctioInfo struct.
3
3
  # Represents a function.
4
4
  class IFunctionInfo < ICallableInfo
5
- def symbol; Lib.g_function_info_get_symbol @gobj; end
6
- def flags; Lib.g_function_info_get_flags @gobj; end
5
+ def symbol
6
+ Lib.g_function_info_get_symbol @gobj
7
+ end
8
+ def flags
9
+ Lib.g_function_info_get_flags @gobj
10
+ end
7
11
 
8
12
  #TODO: Use some sort of bitfield
9
- def method?; flags & 1 != 0 end
10
- def constructor?; flags & 2 != 0 end
11
- def getter?; flags & 4 != 0 end
12
- def setter?; flags & 8 != 0 end
13
- def wraps_vfunc?; flags & 16 != 0 end
14
- def throws?; flags & 32 != 0 end
13
+ def method?
14
+ flags & 1 != 0
15
+ end
16
+ def constructor?
17
+ flags & 2 != 0
18
+ end
19
+ def getter?
20
+ flags & 4 != 0
21
+ end
22
+ def setter?
23
+ flags & 8 != 0
24
+ end
25
+ def wraps_vfunc?
26
+ flags & 16 != 0
27
+ end
28
+ def throws?
29
+ flags & 32 != 0
30
+ end
15
31
  end
16
32
  end
@@ -2,49 +2,91 @@ module GirFFI
2
2
  # Wraps a GIObjectInfo struct.
3
3
  # Represents an object.
4
4
  class IObjectInfo < IRegisteredTypeInfo
5
- def type_name; Lib.g_object_info_get_type_name @gobj; end
6
- def type_init; Lib.g_object_info_get_type_init @gobj; end
7
- def abstract?; Lib.g_object_info_get_abstract @gobj; end
8
- def parent; IObjectInfo.wrap(Lib.g_object_info_get_parent @gobj); end
5
+ def type_name
6
+ Lib.g_object_info_get_type_name @gobj
7
+ end
8
+ def type_init
9
+ Lib.g_object_info_get_type_init @gobj
10
+ end
11
+ def abstract?
12
+ Lib.g_object_info_get_abstract @gobj
13
+ end
14
+ def parent
15
+ IObjectInfo.wrap(Lib.g_object_info_get_parent @gobj)
16
+ end
9
17
 
10
- def n_interfaces; Lib.g_object_info_get_n_interfaces @gobj; end
11
- def interface(index); IInterfaceInfo.wrap(Lib.g_object_info_get_interface @gobj, index); end
18
+ def n_interfaces
19
+ Lib.g_object_info_get_n_interfaces @gobj
20
+ end
21
+ def interface(index)
22
+ IInterfaceInfo.wrap(Lib.g_object_info_get_interface @gobj, index)
23
+ end
12
24
  ##
13
25
  build_array_method :interfaces
14
26
 
15
- def n_fields; Lib.g_object_info_get_n_fields @gobj; end
16
- def field(index); IFieldInfo.wrap(Lib.g_object_info_get_field @gobj, index); end
27
+ def n_fields
28
+ Lib.g_object_info_get_n_fields @gobj
29
+ end
30
+ def field(index)
31
+ IFieldInfo.wrap(Lib.g_object_info_get_field @gobj, index)
32
+ end
17
33
  ##
18
34
  build_array_method :fields
19
35
 
20
- def n_properties; Lib.g_object_info_get_n_properties @gobj; end
21
- def property(index); IPropertyInfo.wrap(Lib.g_object_info_get_property @gobj, index); end
36
+ def n_properties
37
+ Lib.g_object_info_get_n_properties @gobj
38
+ end
39
+ def property(index)
40
+ IPropertyInfo.wrap(Lib.g_object_info_get_property @gobj, index)
41
+ end
22
42
  ##
23
43
  build_array_method :properties, :property
24
44
 
25
- def n_methods; Lib.g_object_info_get_n_methods @gobj; end
26
- def method(index); IFunctionInfo.wrap(Lib.g_object_info_get_method @gobj, index); end
45
+ def n_methods
46
+ Lib.g_object_info_get_n_methods @gobj
47
+ end
48
+ def method(index)
49
+ IFunctionInfo.wrap(Lib.g_object_info_get_method @gobj, index)
50
+ end
27
51
  ##
28
52
  build_array_method :methods
29
53
 
30
- def find_method(name); IFunctionInfo.wrap(Lib.g_object_info_find_method @gobj, name); end
54
+ def find_method(name)
55
+ IFunctionInfo.wrap(Lib.g_object_info_find_method @gobj, name)
56
+ end
31
57
 
32
- def n_signals; Lib.g_object_info_get_n_signals @gobj; end
33
- def signal(index); ISignalInfo.wrap(Lib.g_object_info_get_signal @gobj, index); end
58
+ def n_signals
59
+ Lib.g_object_info_get_n_signals @gobj
60
+ end
61
+ def signal(index)
62
+ ISignalInfo.wrap(Lib.g_object_info_get_signal @gobj, index)
63
+ end
34
64
  ##
35
65
  build_array_method :signals
36
66
 
37
- def n_vfuncs; Lib.g_object_info_get_n_vfuncs @gobj; end
38
- def vfunc(index); IVFuncInfo.wrap(Lib.g_object_info_get_vfunc @gobj, index); end
39
- def find_vfunc; IVFuncInfo.wrap(Lib.g_object_info_find_vfunc @gobj); end
67
+ def n_vfuncs
68
+ Lib.g_object_info_get_n_vfuncs @gobj
69
+ end
70
+ def vfunc(index)
71
+ IVFuncInfo.wrap(Lib.g_object_info_get_vfunc @gobj, index)
72
+ end
73
+ def find_vfunc name
74
+ IVFuncInfo.wrap(Lib.g_object_info_find_vfunc @gobj, name)
75
+ end
40
76
  ##
41
77
  build_array_method :vfuncs
42
78
 
43
- def n_constants; Lib.g_object_info_get_n_constants @gobj; end
44
- def constant(index); IConstantInfo.wrap(Lib.g_object_info_get_constant @gobj, index); end
79
+ def n_constants
80
+ Lib.g_object_info_get_n_constants @gobj
81
+ end
82
+ def constant(index)
83
+ IConstantInfo.wrap(Lib.g_object_info_get_constant @gobj, index)
84
+ end
45
85
  ##
46
86
  build_array_method :constants
47
87
 
48
- def class_struct; IStructInfo.wrap(Lib.g_object_info_get_class_struct @gobj); end
88
+ def class_struct
89
+ IStructInfo.wrap(Lib.g_object_info_get_class_struct @gobj)
90
+ end
49
91
  end
50
92
  end
@@ -3,6 +3,17 @@ module GirFFI
3
3
  # Represents a registered type.
4
4
  # Not implemented yet.
5
5
  class IRegisteredTypeInfo < IBaseInfo
6
+ def type_name
7
+ Lib.g_registered_type_info_get_type_name @gobj
8
+ end
9
+
10
+ def type_init
11
+ Lib.g_registered_type_info_get_type_init @gobj
12
+ end
13
+
14
+ def g_type
15
+ Lib.g_registered_type_info_get_g_type @gobj
16
+ end
6
17
  end
7
18
  end
8
19
 
@@ -1,6 +1,6 @@
1
1
  require 'singleton'
2
2
  require 'gir_ffi/lib'
3
- require 'gir_ffi/g_type'
3
+ require 'gir_ffi/g_object'
4
4
  require 'gir_ffi/g_error'
5
5
  require 'gir_ffi/i_base_info'
6
6
  require 'gir_ffi/i_callable_info'
@@ -52,7 +52,7 @@ module GirFFI
52
52
  }
53
53
 
54
54
  def initialize
55
- GType.init
55
+ GObject.type_init
56
56
  @gobj = Lib::g_irepository_get_default
57
57
  end
58
58
 
@@ -2,6 +2,6 @@ module GirFFI
2
2
  # Wraps a GISignalInfo struct.
3
3
  # Represents a signal.
4
4
  # Not implemented yet.
5
- class ISignalInfo < IBaseInfo
5
+ class ISignalInfo < ICallableInfo
6
6
  end
7
7
  end
@@ -2,21 +2,37 @@ module GirFFI
2
2
  # Wraps a GIStructInfo struct.
3
3
  # Represents a struct.
4
4
  class IStructInfo < IRegisteredTypeInfo
5
- def n_fields; Lib.g_struct_info_get_n_fields @gobj; end
6
- def field(index); IFieldInfo.wrap(Lib.g_struct_info_get_field @gobj, index); end
5
+ def n_fields
6
+ Lib.g_struct_info_get_n_fields @gobj
7
+ end
8
+ def field(index)
9
+ IFieldInfo.wrap(Lib.g_struct_info_get_field @gobj, index)
10
+ end
7
11
 
8
12
  ##
9
13
  build_array_method :fields
10
14
 
11
- def n_methods; Lib.g_struct_info_get_n_methods @gobj; end
12
- def method(index); IFunctionInfo.wrap(Lib.g_struct_info_get_method @gobj, index); end
15
+ def n_methods
16
+ Lib.g_struct_info_get_n_methods @gobj
17
+ end
18
+ def method(index)
19
+ IFunctionInfo.wrap(Lib.g_struct_info_get_method @gobj, index)
20
+ end
13
21
 
14
22
  ##
15
23
  build_array_method :methods
16
24
 
17
- def find_method(name); IFunctionInfo.wrap(Lib.g_struct_info_find_method @gobj, name); end
18
- def size; Lib.g_struct_info_get_size @gobj; end
19
- def alignment; Lib.g_struct_info_get_alignment @gobj; end
20
- def gtype_struct?; Lib.g_struct_info_is_gtype_struct @gobj; end
25
+ def find_method(name)
26
+ IFunctionInfo.wrap(Lib.g_struct_info_find_method @gobj, name)
27
+ end
28
+ def size
29
+ Lib.g_struct_info_get_size @gobj
30
+ end
31
+ def alignment
32
+ Lib.g_struct_info_get_alignment @gobj
33
+ end
34
+ def gtype_struct?
35
+ Lib.g_struct_info_is_gtype_struct @gobj
36
+ end
21
37
  end
22
38
  end
@@ -2,18 +2,34 @@ module GirFFI
2
2
  # Wraps a GITypeInfo struct.
3
3
  # Represents type information, direction, transfer etc.
4
4
  class ITypeInfo < IBaseInfo
5
- def pointer?; Lib.g_type_info_is_pointer @gobj; end
6
- def tag; Lib.g_type_info_get_tag @gobj; end
7
- def param_type(index); ITypeInfo.wrap(Lib.g_type_info_get_param_type @gobj, index); end
5
+ def pointer?
6
+ Lib.g_type_info_is_pointer @gobj
7
+ end
8
+ def tag
9
+ Lib.g_type_info_get_tag @gobj
10
+ end
11
+ def param_type(index)
12
+ ITypeInfo.wrap(Lib.g_type_info_get_param_type @gobj, index)
13
+ end
8
14
  def interface
9
15
  ptr = Lib.g_type_info_get_interface @gobj
10
16
  IRepository.wrap_ibaseinfo_pointer ptr
11
17
  end
12
- def array_length; Lib.g_type_info_get_array_length @gobj; end
13
- def array_fixed_size; Lib.g_type_info_get_array_fixed_size @gobj; end
14
- def zero_terminated?; Lib.g_type_info_is_zero_terminated @gobj; end
15
- def n_error_domains; Lib.g_type_info_get_n_error_domains @gobj; end
16
- def error_domain(index); IErrorDomainInfo.wrap(Lib.g_type_info_get_error_domain @gobj, index); end
18
+ def array_length
19
+ Lib.g_type_info_get_array_length @gobj
20
+ end
21
+ def array_fixed_size
22
+ Lib.g_type_info_get_array_fixed_size @gobj
23
+ end
24
+ def zero_terminated?
25
+ Lib.g_type_info_is_zero_terminated @gobj
26
+ end
27
+ def n_error_domains
28
+ Lib.g_type_info_get_n_error_domains @gobj
29
+ end
30
+ def error_domain(index)
31
+ IErrorDomainInfo.wrap(Lib.g_type_info_get_error_domain @gobj, index)
32
+ end
17
33
  ##
18
34
  build_array_method :error_domains
19
35
 
@@ -3,5 +3,20 @@ module GirFFI
3
3
  # Represents a union.
4
4
  # Not implemented yet.
5
5
  class IUnionInfo < IRegisteredTypeInfo
6
+ def n_fields; Lib.g_union_info_get_n_fields @gobj; end
7
+ def field(index); IFieldInfo.wrap(Lib.g_union_info_get_field @gobj, index); end
8
+
9
+ ##
10
+ build_array_method :fields
11
+
12
+ def n_methods; Lib.g_union_info_get_n_methods @gobj; end
13
+ def method(index); IFunctionInfo.wrap(Lib.g_union_info_get_method @gobj, index); end
14
+
15
+ ##
16
+ build_array_method :methods
17
+
18
+ def find_method(name); IFunctionInfo.wrap(Lib.g_union_info_find_method @gobj, name); end
19
+ def size; Lib.g_union_info_get_size @gobj; end
20
+ def alignment; Lib.g_union_info_get_alignment @gobj; end
6
21
  end
7
22
  end
@@ -2,7 +2,9 @@ module GirFFI
2
2
  # Wraps a GIValueInfo struct.
3
3
  # Represents one of the enum values of an IEnumInfo.
4
4
  class IValueInfo < IBaseInfo
5
- def value; Lib.g_value_info_get_value @gobj; end
5
+ def value
6
+ Lib.g_value_info_get_value @gobj
7
+ end
6
8
  end
7
9
  end
8
10
 
@@ -1,7 +1,18 @@
1
1
  module GirFFI
2
2
  # Wraps a GIVFuncInfo struct.
3
3
  # Represents a virtual function.
4
- # Not implemented yet.
5
4
  class IVFuncInfo < IBaseInfo
5
+ def flags
6
+ Lib.g_vfunc_info_get_flags @gobj
7
+ end
8
+ def offset
9
+ Lib.g_vfunc_info_get_offset @gobj
10
+ end
11
+ def signal
12
+ ISignalInfo.wrap(Lib.g_vfunc_info_get_signal @gobj)
13
+ end
14
+ def invoker
15
+ IFunctionInfo.wrap(Lib.g_vfunc_info_get_invoker @gobj)
16
+ end
6
17
  end
7
18
  end
data/lib/gir_ffi/lib.rb CHANGED
@@ -139,8 +139,18 @@ module GirFFI
139
139
  attach_function :g_field_info_get_type, [:pointer], :pointer
140
140
 
141
141
  # IUnionInfo
142
- # IStructInfo
142
+ attach_function :g_union_info_get_n_fields, [:pointer], :int
143
+ attach_function :g_union_info_get_field, [:pointer, :int], :pointer
144
+ attach_function :g_union_info_get_n_methods, [:pointer], :int
145
+ attach_function :g_union_info_get_method, [:pointer, :int], :pointer
146
+ attach_function :g_union_info_find_method, [:pointer, :string], :pointer
147
+ attach_function :g_union_info_get_size, [:pointer], :int
148
+ attach_function :g_union_info_get_alignment, [:pointer], :int
149
+
143
150
  # IRegisteredTypeInfo
151
+ attach_function :g_registered_type_info_get_type_name, [:pointer], :string
152
+ attach_function :g_registered_type_info_get_type_init, [:pointer], :string
153
+ attach_function :g_registered_type_info_get_g_type, [:pointer], :int
144
154
 
145
155
  # IEnumInfo
146
156
  attach_function :g_enum_info_get_storage_type, [:pointer], :ITypeTag
@@ -170,5 +180,17 @@ module GirFFI
170
180
  attach_function :g_object_info_get_constant, [:pointer, :int], :pointer
171
181
  attach_function :g_object_info_get_class_struct, [:pointer], :pointer
172
182
 
183
+ # IVFuncInfo
184
+
185
+ enum :IVFuncInfoFlags, [
186
+ :must_chain_up, (1 << 0),
187
+ :must_override, (1 << 1),
188
+ :must_not_override, (1 << 2)
189
+ ]
190
+
191
+ attach_function :g_vfunc_info_get_flags, [:pointer], :IVFuncInfoFlags
192
+ attach_function :g_vfunc_info_get_offset, [:pointer], :int
193
+ attach_function :g_vfunc_info_get_signal, [:pointer], :pointer
194
+ attach_function :g_vfunc_info_get_invoker, [:pointer], :pointer
173
195
  end
174
196
  end