Sha256: 4ab9beacc84ee073b04a9cbc47918e343914d1738c263c98e0f806f2af791db7

Contents?: true

Size: 1.12 KB

Versions: 1

Compression:

Stored size: 1.12 KB

Contents

require 'ffi'

module FFI::EZ
  
  def attach_ez *args
    # args is either method_name, [:int] => :int
    # or {'c_name' => :ruby_name, [:int] => :int}
    raise unless args.length <= 2
    method_name = ruby_name = parametersAndReturn = nil
    if args.length == 1 # case {'c_name' => :ruby_name, [:int] => :int}
      args[0].each{|key, setting|
        if key.is_a? Array
          parametersAndReturn = {key => setting}
        else
          method_name = key
          ruby_name = setting
          _dbg unless method_name.is_a? String and ruby_name.is_a? Symbol
          raise unless method_name.is_a? String and ruby_name.is_a? Symbol
        end
      }
    else
      ruby_name = method_name = args.shift
      parametersAndReturn = args.shift
    end
    
    raise unless parametersAndReturn.is_a? Hash # yeah
    raise unless parametersAndReturn.size == 1
    
    attach_function ruby_name, method_name, parametersAndReturn.keys[0], parametersAndReturn.values[0]
  end
  
  def self.extended(base)
    # also want them to have the defaults, if desired
    base.extend FFI::Library
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ffi_ez-0.0.0 lib/ffi_ez.rb