Skip to content

Commit

Permalink
Use ITypeInfo#to_callback_ffitype to define callback FFI argument types
Browse files Browse the repository at this point in the history
  • Loading branch information
mvz committed Mar 23, 2014
1 parent fd396d4 commit db09395
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 2 deletions.
5 changes: 5 additions & 0 deletions lib/gir_ffi/info_ext/i_arg_info.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ def to_ffitype
return :pointer if direction != :in
return argument_type.to_ffitype
end

def to_callback_ffitype
return :pointer if direction != :in
return argument_type.to_callback_ffitype
end
end
end
end
Expand Down
12 changes: 11 additions & 1 deletion lib/gir_ffi/info_ext/i_callback_info.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,18 @@ def to_ffitype
Builder.build_class(self)
end

def argument_ffi_types
args.map { |arg| arg.to_callback_ffitype }
end

def return_ffi_type
return_type.to_callback_ffitype
result = return_type.to_callback_ffitype
# FIXME: Should this be in ITypeInfo#to_callback_ffitype?
if result == GLib::Boolean
:bool
else
result
end
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/gir_ffi/info_ext/i_signal_info.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def gvalue_for_return_value
# types as well?
def ffi_callback_argument_types
types = args.map do |arg|
arg.argument_type.to_callback_ffitype
arg.to_callback_ffitype
end
types.unshift(:pointer).push(:pointer)
end
Expand Down
6 changes: 6 additions & 0 deletions test/integration/generated_gio_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,5 +92,11 @@
pass
end
end

describe "the SocketSourceFunc callback" do
it "can be cast to a native function" do
Gio::SocketSourceFunc.new {|*args| p args}.to_native
end
end
end

0 comments on commit db09395

Please sign in to comment.