Module: Fiddler

Extended by:
Fiddle::Importer, Fiddler
Includes:
Fiddle, Fiddle::CParser, Fiddle::Importer
Included in:
Fiddler
Defined in:
lib/fiddler.rb,
lib/fiddler/version.rb

Constant Summary collapse

LIBSUFFIX =
case RbConfig::CONFIG['host_os'].downcase
when /windows|cgywin/ then 'dll'
when /darwin/         then 'dylib'
else 'so'
end
LIBPATHS =
[ '/usr/local/lib',
'/opt/local/lib',
'/usr/lib64',
File.expand_path("../../ext/leveldb", __FILE__)]
ULONG =
-LONG
LLONG =
LONG_LONG
ULLONG =
-LONG_LONG
UCHAR =
-CHAR
USHORT =
-SHORT
UINT =
-INT
VERSION =
"0.1.0"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



74
75
76
# File 'lib/fiddler.rb', line 74

def self.included(base)
  base.extend self
end

Instance Method Details

#[](val) ⇒ Object



66
67
68
# File 'lib/fiddler.rb', line 66

def [](val)
  cdefs[val]
end

#cdef(name, ret_type, args_types = {}, options = {}) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/fiddler.rb', line 46

def cdef(name, ret_type, args_types={}, options={})
  address     = handler["#{@_prefix}#{name}"] || handler[name.to_s]
  options     = {name: name}.merge(options)
  call_type   = options.delete(:call_type) || Function::DEFAULT
  params      = args_types.keys.join(', ')
  values      = args_types.values
  cdefs[name] = Function.new(address, values, ret_type, call_type, options)

  module_eval <<-RB, __FILE__, __LINE__ + 1
  def #{name}(#{params})
    cdefs[#{name.inspect}].call(#{params})
  end
  module_function #{name.inspect}
  RB
end

#cdefsObject



62
63
64
# File 'lib/fiddler.rb', line 62

def cdefs
  @_cdefs ||= {}
end

#dlload(*libs) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/fiddler.rb', line 25

def dlload(*libs)
  libs.map! do |lib|
    LIBPATHS.map { |l| File.join(l, "#{lib}.#{LIBSUFFIX}") }.
    detect { |l| File.exist?(l) }
  end
  super(*libs)
end

#prefix(value) ⇒ Object



70
71
72
# File 'lib/fiddler.rb', line 70

def prefix(value)
  @_prefix = value
end