Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/ffi/types.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ def self.find_type(name, type_map = nil)
TypeDefs[name]

elsif name.is_a?(DataConverter)
(type_map || TypeDefs)[name] = Type::Mapped.new(name)
tm = (type_map || custom_typedefs)
tm[name] = Type::Mapped.new(name)
else
raise TypeError, "unable to resolve type '#{name}'"
end
Expand Down
13 changes: 13 additions & 0 deletions spec/ffi/struct_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,19 @@ def initialize(a, b)
expect(s[:b]).to eq(0xdeadcafebabe)
end

it "Can use DataConverter in an embedded array" do
class Blub #< FFI::Struct
extend FFI::DataConverter
native_type FFI::Type::INT
end

class Zork < FFI::Struct
layout :c, [Blub, 2], 2
end
z = Zork.new
expect(z[:c].to_a).to eq [0, 0]
end

it "Can use Struct subclass as parameter type" do
expect(module StructParam
extend FFI::Library
Expand Down