gir_ffi 0.2.3 → 0.3.0
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.
- data/History.txt +14 -0
- data/README.rdoc +3 -1
- data/examples/02_hello_world.rb +1 -0
- data/examples/03_upgraded_hello_world.rb +2 -1
- data/examples/05_notification.rb +2 -2
- data/examples/hard_coded.rb +31 -8
- data/lib/ffi-glib/array.rb +1 -1
- data/lib/ffi-glib/container_class_methods.rb +25 -0
- data/lib/ffi-glib/hash_table.rb +41 -38
- data/lib/ffi-glib/list.rb +15 -22
- data/lib/ffi-glib/list_methods.rb +16 -16
- data/lib/ffi-glib/ptr_array.rb +20 -15
- data/lib/ffi-glib/s_list.rb +15 -23
- data/lib/ffi-glib.rb +7 -0
- data/lib/ffi-gobject/base.rb +0 -13
- data/lib/ffi-gobject/object.rb +6 -0
- data/lib/ffi-gobject/ruby_style.rb +21 -0
- data/lib/ffi-gobject.rb +44 -0
- data/lib/ffi-gobject_introspection/i_object_info.rb +7 -0
- data/lib/ffi-gobject_introspection/lib.rb +1 -0
- data/lib/gir_ffi/arg_helper.rb +8 -6
- data/lib/gir_ffi/builder/argument.rb +1 -1
- data/lib/gir_ffi/builder/field.rb +6 -3
- data/lib/gir_ffi/builder/property.rb +28 -0
- data/lib/gir_ffi/builder/type/base.rb +6 -4
- data/lib/gir_ffi/builder/type/interface.rb +1 -0
- data/lib/gir_ffi/builder/type/object.rb +26 -1
- data/lib/gir_ffi/builder/type/registered_type.rb +9 -1
- data/lib/gir_ffi/builder/type/unintrospectable.rb +26 -8
- data/lib/gir_ffi/builder/type/user_defined.rb +119 -0
- data/lib/gir_ffi/builder/type/with_layout.rb +3 -3
- data/lib/gir_ffi/builder.rb +5 -0
- data/lib/gir_ffi/class_base.rb +6 -6
- data/lib/gir_ffi/info_ext/i_property_info.rb +12 -0
- data/lib/gir_ffi/info_ext/i_type_info.rb +4 -0
- data/lib/gir_ffi/user_defined/i_base_info.rb +7 -0
- data/lib/gir_ffi/user_defined/i_object_info.rb +13 -0
- data/lib/gir_ffi/user_defined/i_property_info.rb +9 -0
- data/lib/gir_ffi/user_defined/i_registered_type_info.rb +10 -0
- data/lib/gir_ffi/version.rb +1 -1
- data/lib/gir_ffi.rb +6 -0
- data/tasks/test.rake +12 -2
- data/test/builder_test.rb +0 -124
- data/test/ffi-glib/hash_table_test.rb +0 -14
- data/test/ffi-glib/list_test.rb +0 -13
- data/test/ffi-glib/ptr_array_test.rb +26 -8
- data/test/ffi-glib/s_list_test.rb +4 -4
- data/test/ffi-gobject/g_object_overrides_test.rb +16 -32
- data/test/ffi-gobject/gobject_test.rb +28 -1
- data/test/ffi-gobject/object_class_test.rb +21 -0
- data/test/ffi-gobject/object_test.rb +4 -0
- data/test/ffi-gobject/ruby_style_test.rb +38 -0
- data/test/ffi-gobject_introspection/i_constant_info_test.rb +5 -5
- data/test/ffi-gobject_introspection/i_repository_test.rb +4 -4
- data/test/ffi-gtk/gtk_test.rb +36 -0
- data/test/gir_ffi_test_helper.rb +8 -4
- data/test/integration/derived_classes_test.rb +34 -18
- data/test/integration/generated_gimarshallingtests_test.rb +20 -23
- data/test/integration/generated_gio_test.rb +5 -0
- data/test/integration/generated_gobject_test.rb +2 -2
- data/test/integration/generated_gtk_test.rb +1 -1
- data/test/integration/generated_pango_test.rb +20 -0
- data/test/integration/generated_regress_test.rb +1003 -955
- data/test/integration/pretty_print_test.rb +3 -1
- data/test/test_helper.rb +5 -0
- data/test/type_builder_test.rb +2 -19
- data/test/unit/arg_helper_test.rb +87 -1
- data/test/unit/builder_test.rb +113 -1
- data/test/unit/function_builder_test.rb +6 -5
- data/test/unit/gir_ffi_test.rb +69 -0
- data/test/unit/in_out_pointer_test.rb +3 -3
- data/test/unit/in_pointer_test.rb +1 -1
- data/test/unit/interface_builder_test.rb +16 -0
- data/test/unit/object_type_builder_test.rb +15 -0
- data/test/unit/struct_builder_test.rb +5 -1
- data/test/{unintrospectable_type_builder_test.rb → unit/unintrospectable_type_builder_test.rb} +18 -1
- data/test/unit/user_defined_object_info_test.rb +18 -0
- data/test/unit/user_defined_property_info_test.rb +14 -0
- data/test/unit/user_defined_registered_type_info_test.rb +10 -0
- data/test/unit/user_defined_type_builder_test.rb +41 -0
- metadata +34 -17
- data/tasks/notes.rake +0 -121
- data/tasks/rdoc.rake +0 -9
- data/tasks/yardoc.rake +0 -9
- data/test/arg_helper_test.rb +0 -33
- data/test/gtk_overrides_test.rb +0 -35
- data/test/interface_type_builder_test.rb +0 -17
data/History.txt
CHANGED
@@ -1,3 +1,17 @@
|
|
1
|
+
== 0.3.0 / 2012-04-09
|
2
|
+
|
3
|
+
* Improve process of defining initializers in derived classes.
|
4
|
+
* Make interfaces know their GType.
|
5
|
+
* Make classes created by the Unintrospectable builder know their GType.
|
6
|
+
* Create property accessors instead of field accessors for GObjects.
|
7
|
+
* Add Ruby-style getter and setter methods (by Antonio Terceiro).
|
8
|
+
* Add #signal_connect instance method (by Antonio Terceiro).
|
9
|
+
* Make GirFFI's tests pass with gobject-introspection 0.10.
|
10
|
+
* Improve unintrospectable type handling.
|
11
|
+
* Bug fixes and refactorings.
|
12
|
+
* Start implementing #define_type, for creating descendent types that
|
13
|
+
the GObject system knows about.
|
14
|
+
|
1
15
|
== 0.2.3 / 2011-12-31
|
2
16
|
|
3
17
|
* Fix issue #7: methods that take GValues will autoconvert other values.
|
data/README.rdoc
CHANGED
@@ -4,6 +4,8 @@ by Matijs van Zuijlen
|
|
4
4
|
|
5
5
|
http://www.github.com/mvz/ruby-gir-ffi
|
6
6
|
|
7
|
+
{<img src="https://secure.travis-ci.org/mvz/ruby-gir-ffi.png" />}[http://travis-ci.org/mvz/ruby-gir-ffi]
|
8
|
+
|
7
9
|
== Description
|
8
10
|
|
9
11
|
Ruby bindings for GNOME using the GObject Introspection Repository.
|
@@ -86,7 +88,7 @@ If you want to send pull requests or patches, please:
|
|
86
88
|
|
87
89
|
== License
|
88
90
|
|
89
|
-
Copyright (c) 2009--
|
91
|
+
Copyright (c) 2009--2012 Matijs van Zuijlen
|
90
92
|
|
91
93
|
GirFFI is free software, distributed under the terms of the GNU Lesser
|
92
94
|
General Public License, version 2.1 or later. See the file COPYING.LIB for
|
data/examples/02_hello_world.rb
CHANGED
@@ -12,13 +12,14 @@ callback = lambda { |widget, data|
|
|
12
12
|
Gtk.init
|
13
13
|
|
14
14
|
win = Gtk::Window.new(:toplevel)
|
15
|
-
win.
|
15
|
+
win.title= "Hello Buttons!"
|
16
16
|
|
17
17
|
GObject.signal_connect win, "delete-event" do
|
18
18
|
Gtk.main_quit
|
19
19
|
false
|
20
20
|
end
|
21
21
|
|
22
|
+
# FIXME: #border_width= should work
|
22
23
|
win.set_border_width 10
|
23
24
|
|
24
25
|
box = Gtk::HBox.new(false, 0)
|
data/examples/05_notification.rb
CHANGED
@@ -12,8 +12,8 @@ Notify.init "notification test"
|
|
12
12
|
|
13
13
|
# Basic set up of the notification.
|
14
14
|
nf = Notify::Notification.new "Hello!", "Hi there.", "gtk-dialog-info"
|
15
|
-
nf.
|
16
|
-
nf.
|
15
|
+
nf.timeout = 3000
|
16
|
+
nf.urgency = :critical
|
17
17
|
|
18
18
|
# Show a button 'Test' in the notification, with a callback function.
|
19
19
|
nf.add_action "test", "Test", Proc.new { |obj, action, user_data|
|
data/examples/hard_coded.rb
CHANGED
@@ -106,25 +106,48 @@ module Gtk
|
|
106
106
|
end
|
107
107
|
|
108
108
|
class Button < Container
|
109
|
-
def initialize ptr
|
110
|
-
@gobj = ptr
|
111
|
-
end
|
112
109
|
class << self
|
113
110
|
alias :real_new :new
|
114
111
|
end
|
112
|
+
|
113
|
+
def self.new *args
|
114
|
+
obj = self.real_new *args
|
115
|
+
ptr = Lib.gtk_button_new()
|
116
|
+
obj.instance_variable_set :@gobj, ptr
|
117
|
+
obj
|
118
|
+
end
|
119
|
+
|
120
|
+
def self.new_with_label text, *args
|
121
|
+
obj = self.real_new *args
|
122
|
+
ptr = Lib.gtk_button_new_with_label(text)
|
123
|
+
obj.instance_variable_set :@gobj, ptr
|
124
|
+
obj
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
class MyButton < Button
|
129
|
+
def initialize sym
|
130
|
+
puts "Initializing a #{self.class} with symbol #{sym}"
|
131
|
+
end
|
132
|
+
|
115
133
|
def self.new
|
116
|
-
|
134
|
+
super :foo
|
117
135
|
end
|
118
|
-
|
119
|
-
|
136
|
+
|
137
|
+
def self.new_with_label sym
|
138
|
+
super "Hello world", sym
|
120
139
|
end
|
121
140
|
end
|
122
141
|
end
|
123
142
|
|
124
143
|
(my_len, my_args) = Gtk.init ARGV.length + 1, [$0, *ARGV]
|
125
|
-
p my_len, my_args
|
144
|
+
p [my_len, my_args]
|
126
145
|
win = Gtk::Window.new(:GTK_WINDOW_TOPLEVEL)
|
127
|
-
|
146
|
+
|
147
|
+
#btn = Gtk::Button.new_with_label('Hello World')
|
148
|
+
#btn = Gtk::MyButton.new
|
149
|
+
btn = Gtk::MyButton.new_with_label :foobar2
|
150
|
+
|
128
151
|
win.add btn
|
129
152
|
|
130
153
|
quit_prc = Proc.new { Gtk.main_quit }
|
data/lib/ffi-glib/array.rb
CHANGED
@@ -0,0 +1,25 @@
|
|
1
|
+
module GLib
|
2
|
+
module ContainerClassMethods
|
3
|
+
def wrap typespec, ptr
|
4
|
+
super(ptr).tap do |it|
|
5
|
+
break if it.nil?
|
6
|
+
it.reset_typespec typespec
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def from typespec, it
|
11
|
+
case it
|
12
|
+
when nil
|
13
|
+
nil
|
14
|
+
when FFI::Pointer
|
15
|
+
wrap typespec, it
|
16
|
+
when self
|
17
|
+
it.reset_typespec typespec
|
18
|
+
else
|
19
|
+
from_enumerable typespec, it
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
|
data/lib/ffi-glib/hash_table.rb
CHANGED
@@ -1,9 +1,14 @@
|
|
1
|
+
require 'ffi-glib/container_class_methods'
|
2
|
+
|
1
3
|
module GLib
|
2
4
|
load_class :HashTable
|
3
5
|
|
4
6
|
# Overrides for GHashTable, GLib's hash table implementation.
|
5
7
|
class HashTable
|
6
8
|
include Enumerable
|
9
|
+
extend ContainerClassMethods
|
10
|
+
|
11
|
+
# TODO: Restructure so these can become attr_readers.
|
7
12
|
attr_accessor :key_type
|
8
13
|
attr_accessor :value_type
|
9
14
|
|
@@ -27,50 +32,48 @@ module GLib
|
|
27
32
|
end
|
28
33
|
|
29
34
|
class << self
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
else
|
38
|
-
[nil, nil]
|
39
|
-
end
|
40
|
-
wrap [keytype, valtype], Lib.g_hash_table_new(hash_fn, eq_fn)
|
41
|
-
end
|
35
|
+
remove_method :new
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.new keytype, valtype
|
39
|
+
wrap [keytype, valtype], Lib.g_hash_table_new(
|
40
|
+
hash_function_for(keytype), equality_function_for(keytype))
|
41
|
+
end
|
42
42
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
43
|
+
def reset_typespec typespec
|
44
|
+
self.key_type, self.value_type = *typespec
|
45
|
+
self
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.from_enumerable typespec, hash
|
49
|
+
ghash = self.new(*typespec)
|
50
|
+
hash.each do |key, val|
|
51
|
+
ghash.insert key, val
|
50
52
|
end
|
53
|
+
ghash
|
54
|
+
end
|
51
55
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
return hash
|
59
|
-
end
|
60
|
-
ghash = self.new keytype, valtype
|
61
|
-
hash.each do |key, val|
|
62
|
-
ghash.insert key, val
|
63
|
-
end
|
64
|
-
ghash
|
56
|
+
def self.hash_function_for keytype
|
57
|
+
case keytype
|
58
|
+
when :utf8
|
59
|
+
FFI::Function.new(:uint, [:pointer], find_support_funtion("g_str_hash"))
|
60
|
+
else
|
61
|
+
nil
|
65
62
|
end
|
63
|
+
end
|
66
64
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
65
|
+
def self.equality_function_for keytype
|
66
|
+
case keytype
|
67
|
+
when :utf8
|
68
|
+
FFI::Function.new(:int, [:pointer, :pointer], find_support_funtion("g_str_equal"))
|
69
|
+
else
|
70
|
+
nil
|
73
71
|
end
|
74
72
|
end
|
73
|
+
|
74
|
+
def self.find_support_funtion name
|
75
|
+
lib = ::GLib::Lib.ffi_libraries.first
|
76
|
+
lib.find_function(name)
|
77
|
+
end
|
75
78
|
end
|
76
79
|
end
|
data/lib/ffi-glib/list.rb
CHANGED
@@ -7,34 +7,27 @@ module GLib
|
|
7
7
|
class List
|
8
8
|
include ListMethods
|
9
9
|
|
10
|
-
# Override default field accessors.
|
11
|
-
undef :next
|
12
|
-
undef :data
|
13
|
-
|
14
|
-
alias :next :tail
|
15
|
-
alias :data :head
|
16
|
-
|
17
10
|
class << self
|
18
|
-
|
19
|
-
|
20
|
-
_real_new(FFI::Pointer.new(0)).tap {|it|
|
21
|
-
it.element_type = type}
|
22
|
-
end
|
11
|
+
remove_method :new
|
12
|
+
end
|
23
13
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
end
|
30
|
-
arr.inject(self.new type) { |lst, val|
|
31
|
-
lst.append val }
|
14
|
+
def self.new type
|
15
|
+
_real_new.tap do |it|
|
16
|
+
struct = ffi_structure.new(FFI::Pointer.new(0))
|
17
|
+
it.instance_variable_set :@struct, struct
|
18
|
+
it.element_type = type
|
32
19
|
end
|
33
20
|
end
|
34
21
|
|
22
|
+
def self.from_enumerable type, arr
|
23
|
+
arr.inject(self.new type) { |lst, val|
|
24
|
+
lst.append val }
|
25
|
+
end
|
26
|
+
|
35
27
|
def append data
|
36
|
-
|
37
|
-
|
28
|
+
elm_t = element_type
|
29
|
+
data_ptr = GirFFI::InPointer.from(elm_t, data)
|
30
|
+
self.class.wrap(elm_t, Lib.g_list_append(self, data_ptr))
|
38
31
|
end
|
39
32
|
end
|
40
33
|
end
|
@@ -1,10 +1,22 @@
|
|
1
|
+
require 'ffi-glib/container_class_methods'
|
2
|
+
|
1
3
|
module GLib
|
2
4
|
module ListMethods
|
3
5
|
include Enumerable
|
4
6
|
attr_accessor :element_type
|
5
7
|
|
6
8
|
def self.included base
|
7
|
-
base.extend
|
9
|
+
base.extend ContainerClassMethods
|
10
|
+
# Override default field accessors.
|
11
|
+
replace_method base, :next, :tail
|
12
|
+
replace_method base, :data, :head
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.replace_method base, old, new
|
16
|
+
base.class_eval do
|
17
|
+
remove_method old
|
18
|
+
alias_method old, new
|
19
|
+
end
|
8
20
|
end
|
9
21
|
|
10
22
|
def each
|
@@ -25,21 +37,9 @@ module GLib
|
|
25
37
|
GirFFI::ArgHelper.cast_from_pointer(element_type, @struct[:data])
|
26
38
|
end
|
27
39
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
break if it.nil?
|
32
|
-
it.element_type = elmttype
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
def from elmttype, it
|
37
|
-
if it.is_a? FFI::Pointer
|
38
|
-
wrap elmttype, it
|
39
|
-
else
|
40
|
-
from_array elmttype, it
|
41
|
-
end
|
42
|
-
end
|
40
|
+
def reset_typespec typespec
|
41
|
+
self.element_type = typespec
|
42
|
+
self
|
43
43
|
end
|
44
44
|
end
|
45
45
|
end
|
data/lib/ffi-glib/ptr_array.rb
CHANGED
@@ -9,18 +9,18 @@ module GLib
|
|
9
9
|
attr_accessor :element_type
|
10
10
|
|
11
11
|
class << self
|
12
|
-
|
13
|
-
def new type
|
14
|
-
wrap(Lib.g_ptr_array_new).tap {|it|
|
15
|
-
it.element_type = type}
|
16
|
-
end
|
17
|
-
|
12
|
+
remove_method :new
|
18
13
|
# Remove stub generated by builder.
|
19
|
-
|
14
|
+
remove_method :add if method_defined? :add
|
15
|
+
end
|
20
16
|
|
21
|
-
|
22
|
-
|
23
|
-
|
17
|
+
def self.new type
|
18
|
+
wrap(Lib.g_ptr_array_new).tap {|it|
|
19
|
+
it.element_type = type}
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.add array, data
|
23
|
+
array.add data
|
24
24
|
end
|
25
25
|
|
26
26
|
def add data
|
@@ -28,12 +28,17 @@ module GLib
|
|
28
28
|
Lib.g_ptr_array_add self, ptr
|
29
29
|
end
|
30
30
|
|
31
|
+
# Re-implementation of the g_ptr_array_index macro
|
32
|
+
def index idx
|
33
|
+
sz = FFI.type_size :pointer
|
34
|
+
ptr = @struct[:pdata].get_pointer(idx * sz)
|
35
|
+
GirFFI::ArgHelper.cast_from_pointer(element_type, ptr)
|
36
|
+
end
|
37
|
+
|
31
38
|
def each
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
}
|
36
|
-
Lib.g_ptr_array_foreach self.to_ptr, prc, nil
|
39
|
+
@struct[:len].times.each do |idx|
|
40
|
+
yield index(idx)
|
41
|
+
end
|
37
42
|
end
|
38
43
|
end
|
39
44
|
end
|
data/lib/ffi-glib/s_list.rb
CHANGED
@@ -7,35 +7,27 @@ module GLib
|
|
7
7
|
class SList
|
8
8
|
include ListMethods
|
9
9
|
|
10
|
-
# Override default field accessors.
|
11
|
-
undef :next
|
12
|
-
undef :data
|
13
|
-
|
14
|
-
alias :next :tail
|
15
|
-
alias :data :head
|
16
|
-
|
17
10
|
class << self
|
18
|
-
|
19
|
-
|
20
|
-
_real_new(FFI::Pointer.new(0)).tap {|it|
|
21
|
-
it.element_type = type}
|
22
|
-
end
|
11
|
+
remove_method :new
|
12
|
+
end
|
23
13
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
end
|
30
|
-
arr.reverse.inject(self.new type) { |lst, val|
|
31
|
-
lst.prepend val }
|
14
|
+
def self.new type
|
15
|
+
_real_new.tap do |it|
|
16
|
+
struct = ffi_structure.new(FFI::Pointer.new(0))
|
17
|
+
it.instance_variable_set :@struct, struct
|
18
|
+
it.element_type = type
|
32
19
|
end
|
33
20
|
end
|
34
21
|
|
35
|
-
def
|
36
|
-
|
37
|
-
|
22
|
+
def self.from_enumerable type, arr
|
23
|
+
arr.reverse.inject(self.new type) { |lst, val|
|
24
|
+
lst.prepend val }
|
38
25
|
end
|
39
26
|
|
27
|
+
def prepend data
|
28
|
+
elm_t = element_type
|
29
|
+
data_ptr = GirFFI::InPointer.from(elm_t, data)
|
30
|
+
self.class.wrap(elm_t, Lib.g_slist_prepend(self, data_ptr))
|
31
|
+
end
|
40
32
|
end
|
41
33
|
end
|
data/lib/ffi-glib.rb
CHANGED
@@ -9,6 +9,11 @@ require 'ffi-glib/ptr_array'
|
|
9
9
|
require 'ffi-glib/strv'
|
10
10
|
|
11
11
|
module GLib
|
12
|
+
# FIXME: Remove eventually.
|
13
|
+
def self.main_loop_new context, is_running
|
14
|
+
::GLib::MainLoop.wrap(::GLib::Lib.g_main_loop_new context, is_running)
|
15
|
+
end
|
16
|
+
|
12
17
|
load_class :HFunc
|
13
18
|
load_class :HashFunc
|
14
19
|
load_class :EqualFunc
|
@@ -38,5 +43,7 @@ module GLib
|
|
38
43
|
attach_function :g_ptr_array_add, [:pointer, :pointer], :void
|
39
44
|
attach_function :g_ptr_array_foreach, [:pointer, Func, :pointer],
|
40
45
|
:pointer
|
46
|
+
|
47
|
+
attach_function :g_main_loop_new, [:pointer, :bool], :pointer
|
41
48
|
end
|
42
49
|
end
|
data/lib/ffi-gobject/base.rb
CHANGED
@@ -22,17 +22,4 @@ module GObject
|
|
22
22
|
TYPE_OBJECT = type_from_name("GObject")
|
23
23
|
TYPE_GTYPE = type_from_name("GType")
|
24
24
|
TYPE_VARIANT = type_from_name("GVariant")
|
25
|
-
TYPE_STRV = GLib.strv_get_type
|
26
|
-
TYPE_HASH_TABLE = type_from_name("GHashTable")
|
27
|
-
|
28
|
-
TYPE_TAG_TO_GTYPE = {
|
29
|
-
:void => TYPE_NONE,
|
30
|
-
:gboolean => TYPE_BOOLEAN,
|
31
|
-
:gint32 => TYPE_INT,
|
32
|
-
:gfloat => TYPE_FLOAT,
|
33
|
-
:gdouble => TYPE_DOUBLE,
|
34
|
-
:utf8 => TYPE_STRING,
|
35
|
-
:ghash => TYPE_HASH_TABLE,
|
36
|
-
:glist => TYPE_POINTER
|
37
|
-
}
|
38
25
|
end
|
data/lib/ffi-gobject/object.rb
CHANGED
@@ -1,8 +1,14 @@
|
|
1
|
+
require 'ffi-gobject/ruby_style'
|
2
|
+
|
1
3
|
module GObject
|
2
4
|
load_class :Object
|
3
5
|
|
4
6
|
# Overrides for GObject, GObject's generic base class.
|
5
7
|
class Object
|
8
|
+
|
9
|
+
include RubyStyle
|
10
|
+
|
11
|
+
_setup_method "new"
|
6
12
|
_setup_instance_method "get_property"
|
7
13
|
_setup_instance_method "set_property"
|
8
14
|
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module GObject
|
2
|
+
|
3
|
+
module RubyStyle
|
4
|
+
|
5
|
+
def method_missing(method, *args)
|
6
|
+
if respond_to?("get_#{method}")
|
7
|
+
return send("get_#{method}", *args)
|
8
|
+
end
|
9
|
+
if method.to_s =~ /(.*)=$/ && respond_to?("set_#{$1}")
|
10
|
+
return send("set_#{$1}", *args)
|
11
|
+
end
|
12
|
+
super
|
13
|
+
end
|
14
|
+
|
15
|
+
def signal_connect(event, &block)
|
16
|
+
GObject.signal_connect(self, event, &block)
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
data/lib/ffi-gobject.rb
CHANGED
@@ -8,6 +8,7 @@ require 'ffi-gobject/closure'
|
|
8
8
|
require 'ffi-gobject/object'
|
9
9
|
require 'ffi-gobject/ruby_closure'
|
10
10
|
require 'ffi-gobject/helper'
|
11
|
+
require 'gir_ffi/builder/type/user_defined'
|
11
12
|
|
12
13
|
module GObject
|
13
14
|
def self.type_init
|
@@ -40,6 +41,16 @@ module GObject
|
|
40
41
|
type_from_instance_pointer instance.to_ptr
|
41
42
|
end
|
42
43
|
|
44
|
+
def self.object_class_from_instance instance
|
45
|
+
object_class_from_instance_pointer instance.to_ptr
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.object_class_from_instance_pointer inst_ptr
|
49
|
+
return nil if inst_ptr.null?
|
50
|
+
klsptr = inst_ptr.get_pointer 0
|
51
|
+
ObjectClass.wrap klsptr
|
52
|
+
end
|
53
|
+
|
43
54
|
_setup_method :signal_emitv
|
44
55
|
|
45
56
|
def self.signal_lookup_from_instance signal, object
|
@@ -65,10 +76,18 @@ module GObject
|
|
65
76
|
Lib.g_signal_connect_data object, signal, callback, data_ptr, nil, 0
|
66
77
|
end
|
67
78
|
|
79
|
+
def self.param_spec_int(name, nick, blurb, minimum, maximum,
|
80
|
+
default_value, flags)
|
81
|
+
ptr = Lib.g_param_spec_int(name, nick, blurb, minimum, maximum,
|
82
|
+
default_value, flags)
|
83
|
+
ParamSpecInt.wrap(ptr)
|
84
|
+
end
|
85
|
+
|
68
86
|
load_class :Callback
|
69
87
|
load_class :ClosureNotify
|
70
88
|
load_class :ConnectFlags
|
71
89
|
load_class :ClosureMarshal
|
90
|
+
load_class :ParamFlags
|
72
91
|
|
73
92
|
module Lib
|
74
93
|
attach_function :g_type_init, [], :void
|
@@ -77,12 +96,37 @@ module GObject
|
|
77
96
|
attach_function :g_object_unref, [:pointer], :void
|
78
97
|
attach_function :g_object_is_floating, [:pointer], :bool
|
79
98
|
|
99
|
+
# XXX: For older GObject/gobject-introspection.
|
100
|
+
unless method_defined? :g_object_newv
|
101
|
+
attach_function :g_object_newv, [:size_t, :uint, :pointer], :pointer
|
102
|
+
end
|
103
|
+
|
104
|
+
attach_function :g_strv_get_type, [], :size_t
|
105
|
+
attach_function :g_hash_table_get_type, [], :size_t
|
106
|
+
|
80
107
|
attach_function :g_signal_connect_data,
|
81
108
|
[:pointer, :string, Callback, :pointer, ClosureNotify,
|
82
109
|
ConnectFlags],
|
83
110
|
:ulong
|
84
111
|
attach_function :g_closure_set_marshal,
|
85
112
|
[:pointer, ClosureMarshal], :void
|
113
|
+
|
114
|
+
attach_function :g_param_spec_int,
|
115
|
+
[:string, :string, :string, :int32, :int32, :int32, ParamFlags],
|
116
|
+
:pointer
|
86
117
|
end
|
87
118
|
|
119
|
+
TYPE_STRV = Lib.g_strv_get_type
|
120
|
+
TYPE_HASH_TABLE = Lib.g_hash_table_get_type
|
121
|
+
|
122
|
+
TYPE_TAG_TO_GTYPE = {
|
123
|
+
:void => TYPE_NONE,
|
124
|
+
:gboolean => TYPE_BOOLEAN,
|
125
|
+
:gint32 => TYPE_INT,
|
126
|
+
:gfloat => TYPE_FLOAT,
|
127
|
+
:gdouble => TYPE_DOUBLE,
|
128
|
+
:utf8 => TYPE_STRING,
|
129
|
+
:ghash => TYPE_HASH_TABLE,
|
130
|
+
:glist => TYPE_POINTER
|
131
|
+
}
|
88
132
|
end
|
@@ -5,12 +5,19 @@ module GObjectIntrospection
|
|
5
5
|
def type_name
|
6
6
|
Lib.g_object_info_get_type_name @gobj
|
7
7
|
end
|
8
|
+
|
8
9
|
def type_init
|
9
10
|
Lib.g_object_info_get_type_init @gobj
|
10
11
|
end
|
12
|
+
|
11
13
|
def abstract?
|
12
14
|
Lib.g_object_info_get_abstract @gobj
|
13
15
|
end
|
16
|
+
|
17
|
+
def fundamental?
|
18
|
+
Lib.g_object_info_get_fundamental @gobj
|
19
|
+
end
|
20
|
+
|
14
21
|
def parent
|
15
22
|
IObjectInfo.wrap(Lib.g_object_info_get_parent @gobj)
|
16
23
|
end
|
@@ -207,6 +207,7 @@ module GObjectIntrospection
|
|
207
207
|
attach_function :g_object_info_get_n_constants, [:pointer], :int
|
208
208
|
attach_function :g_object_info_get_constant, [:pointer, :int], :pointer
|
209
209
|
attach_function :g_object_info_get_class_struct, [:pointer], :pointer
|
210
|
+
attach_function :g_object_info_get_fundamental, [:pointer], :bool
|
210
211
|
|
211
212
|
# IVFuncInfo
|
212
213
|
|