module GirFFI::Builder

Builds modules and classes based on information found in the introspection repository. Call its ::build_module and ::build_class methods to create the modules and classes used in your program.

Public Class Methods

attach_ffi_function(lib, info) click to toggle source

TODO: Move elsewhere, perhaps to FunctionBuilder.

# File lib/gir_ffi/builder.rb, line 46
def self.attach_ffi_function(lib, info)
  sym = info.symbol
  return if lib.method_defined? sym

  lib.attach_function sym, info.argument_ffi_types, info.return_ffi_type
end
build_by_gtype(gtype) click to toggle source
# File lib/gir_ffi/builder.rb, line 20
def self.build_by_gtype(gtype)
  info = GObjectIntrospection::IRepository.default.find_by_gtype gtype
  info ||= case GObject.type_fundamental gtype
           when GObject::TYPE_BOXED
             UnintrospectableBoxedInfo.new gtype
           when GObject::TYPE_OBJECT
             UnintrospectableTypeInfo.new gtype
           end

  build_class info
end
build_class(info) click to toggle source
# File lib/gir_ffi/builder.rb, line 16
def self.build_class(info)
  Builders::TypeBuilder.build(info)
end
build_module(namespace, version = nil) click to toggle source
# File lib/gir_ffi/builder.rb, line 32
def self.build_module(namespace, version = nil)
  module_name = namespace.sub(/\A./, &:upcase)
  if const_defined? module_name
    modul = const_get module_name
    unless modul.const_defined? :GIR_FFI_BUILDER
      raise "The module #{module_name} was already defined elsewhere"
    end
  end
  Builders::ModuleBuilder.new(module_name,
                              namespace: namespace,
                              version: version).generate
end