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']
ULONG =
-LONG
LLONG =
LONG_LONG
ULLONG =
-LONG_LONG
UCHAR =
-CHAR
USHORT =
-SHORT
UINT =
-INT
VERSION =
"0.1.2"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



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

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

Instance Method Details

#[](val) ⇒ Object



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

def [](val)
  cdefs[val]
end

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



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

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 "  def \#{name}(\#{params})\n    cdefs[\#{name.inspect}].call(\#{params})\n  end\n  module_function \#{name.inspect}\n  RB\nend\n", __FILE__, __LINE__ + 1

#cdefsObject



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

def cdefs
  @_cdefs ||= {}
end

#dlload(*libs) ⇒ Object



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

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



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

def prefix(value)
  @_prefix = value
end