Module: FFI::EZ

Defined in:
lib/ffi_ez.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(base) ⇒ Object



32
33
34
35
# File 'lib/ffi_ez.rb', line 32

def self.extended(base)
  # also want them to have the defaults, if desired
  base.extend FFI::Library
end

Instance Method Details

#attach_ez(*args) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/ffi_ez.rb', line 5

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