module FT::LibBase

Constants

ERROR_CODE

Public Class Methods

extended(c) click to toggle source
# File lib/ft-ffi/lib_base.rb, line 201
def self.extended(c)
  c.extend FFI::Library
  instance_variables.each do |v|
    value = instance_variable_get(v)
    value = value.dup unless value.is_a?(Integer) || value.is_a?(Symbol)
    c.instance_variable_set(v, value)
  end
end

Public Instance Methods

define_prefix(prefix, target_enum) click to toggle source
# File lib/ft-ffi/lib_base.rb, line 194
def define_prefix(prefix, target_enum)
  c = const_defined?(prefix) ? const_get(prefix) : const_set(prefix, Module.new)
  target_enum.to_h.each do |k, v|
    c.const_set(k, v) unless const_defined? k
  end
end
ft_function(method_name, *args) click to toggle source
# File lib/ft-ffi/lib_base.rb, line 181
def ft_function(method_name, *args)
  function_name = "FT_#{method_name}"
  attach_function function_name, args, :FT_Error
  (class << self; self end).send('define_method', method_name) do |*args2|
    error = send(function_name, *args2)
    return if error == 0
    msg = "#{function_name} api returned error code 0x#{error.to_s(16)}"
    error_array = ERROR_CODE[error]
    msg += " #{error_array[0]} #{error_array[1].inspect}" if error_array
    raise FreeTypeError, msg
  end
end