module Fiddley::Library
Constants
- LIBC
- LIBM
- LIBPREFIX
- LIBSUFFIX
Public Instance Methods
attach_function(rname, cname, params, ret = nil, blocking: false)
click to toggle source
# File lib/fiddley/library.rb, line 43 def attach_function(rname, cname, params, ret = nil, blocking: false) if ret.nil? ret = params params = cname cname = rname end extern "#{type2str(ret)} #{cname}(#{params.map{|e| type2str(e)}.join(', ')})", @convention case ret when :string wrap_function(cname, &:to_s) when :pointer wrap_function(cname) do |result| Fiddley::MemoryPointer.new(ret, result) end end if cname != rname instance_eval <<-end alias #{rname.inspect} #{cname.inspect} end end end
enum(*args)
click to toggle source
# File lib/fiddley/library.rb, line 75 def enum(*args) if args[1].is_a?(Array) tag = args.shift else tag = nil end if args[0].is_a?(Array) args = args[0] end @enums ||= [] @enums << Fiddley::Enum.new(args, tag) end
enum_type(key)
click to toggle source
# File lib/fiddley/library.rb, line 98 def enum_type(key) @enums ||= [] @enums.find{|enum| enum.tag == key} end
enum_value(key)
click to toggle source
# File lib/fiddley/library.rb, line 88 def enum_value(key) @enums ||= [] enum = @enums.find{|enum| enum[key]} if enum enum[key] else nil end end
extended(mod)
click to toggle source
# File lib/fiddley/library.rb, line 35 def extended(mod) @convention = nil end
ffi_convention(conv)
click to toggle source
# File lib/fiddley/library.rb, line 39 def ffi_convention(conv) @convention = conv end
ffi_lib(*args)
click to toggle source
# File lib/fiddley/library.rb, line 11 def ffi_lib(*args) args.each do |soes| soes = [soes] unless soes.is_a?(Array) loaded = false soes.each do |so| begin begin dlload so rescue Fiddle::DLError begin dlload LIBPREFIX + so rescue Fiddle::DLError dlload LIBPREFIX + so + "." + LIBSUFFIX end end loaded = true break rescue Fiddle::DLError end end raise Fiddle::DLError, "can't load #{soes.join(' or ')}" unless loaded end end
Private Instance Methods
wrap_function(cname, &blk)
click to toggle source
# File lib/fiddley/library.rb, line 65 def wrap_function(cname, &blk) tname = (cname.to_s + '+').to_sym instance_eval <<-end alias #{tname.inspect} #{cname.inspect} end define_singleton_method(cname) do |*args| blk.call(__send__(tname, *args)) end end