Module: AAlib::Foreign

Defined in:
lib/aalib.rb

Overview

:nodoc:all

Constant Summary collapse

LIB =
DL.tryopen ['libaa.so.1', 'libaa.so', 'libaa']

Class Method Summary collapse

Class Method Details

.attach_function(lib, func, sym, sig) ⇒ Object

Defines a method named sym that calls the given function from DL:Handle lib using the DL function signature sig. This method is modeled after a similar method in Rubinius’ FFI.



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/aalib.rb', line 66

def attach_function(lib, func, sym, sig)
  self.class.send(:define_method, sym) do |*args|
    # print "calling #{func}("
    # if args
    #   argstr = args.collect do |a|
    #     if a.kind_of? Array
    #       a.inspect
    #     elsif a.kind_of? DL::PtrData
    #       a.class
    #     else
    #       "'#{a}'"
    #     end
    #   end
    #   print argstr.join(', ')
    # end
    # print ")\n"
    lib[func, sig].call(*args)
  end
end

.attach_global(lib, global, sym) ⇒ Object

Defines a method named sym that returns the global variable global from DL:Handle lib.



89
90
91
92
93
# File 'lib/aalib.rb', line 89

def attach_global(lib, global, sym)
  self.class.send(:define_method, sym) do
    lib[global]
  end
end