Module: FFI::Library
- Defined in:
- lib/ffi-compiler/fake_ffi/ffi.rb
Constant Summary collapse
- TypeMap =
{}
Class Method Summary collapse
Instance Method Summary collapse
- #attach_function(name, func, args, returns = nil, options = nil) ⇒ Object
- #callback(*args) ⇒ Object
- #ffi_lib(*args) ⇒ Object
- #find_type(type) ⇒ Object
Class Method Details
Instance Method Details
#attach_function(name, func, args, returns = nil, options = nil) ⇒ Object
171 172 173 174 175 176 |
# File 'lib/ffi-compiler/fake_ffi/ffi.rb', line 171 def attach_function(name, func, args, returns = nil, = nil) mname, a2, a3, a4, a5 = name, func, args, returns, cname, arg_types, ret_type, opts = (a4 && (a2.is_a?(String) || a2.is_a?(Symbol))) ? [ a2, a3, a4, a5 ] : [ mname.to_s, a2, a3, a4 ] arg_types = arg_types.map { |e| find_type(e) } FFI.exporter.attach(mname, cname, find_type(ret_type), arg_types) end |
#callback(*args) ⇒ Object
182 183 184 185 186 187 188 189 190 191 |
# File 'lib/ffi-compiler/fake_ffi/ffi.rb', line 182 def callback(*args) name, params, ret = if args.length == 3 args else [ nil, args[0], args[1] ] end native_params = params.map { |e| find_type(e) } cb = FFI::CallbackInfo.new(find_type(ret), native_params) FFI.exporter.callback(name, cb) if name end |
#ffi_lib(*args) ⇒ Object
178 179 180 |
# File 'lib/ffi-compiler/fake_ffi/ffi.rb', line 178 def ffi_lib(*args) end |
#find_type(type) ⇒ Object
194 195 196 197 198 199 200 201 202 203 |
# File 'lib/ffi-compiler/fake_ffi/ffi.rb', line 194 def find_type(type) t = TypeMap[type] return t unless t.nil? if type.is_a?(Class) && type < Struct return TypeMap[type] = StructByReference.new(type) end TypeMap[type] = FFI.find_type(type) end |