Sha256: 87ec07e7ab6a2ab7e2b0aff74a6bae8eac7e3f1e52773629e4e6705eeee45060

Contents?: true

Size: 898 Bytes

Versions: 3

Compression:

Stored size: 898 Bytes

Contents

module H3
  module Bindings
    # Base for FFI Bindings.
    #
    # When extended, this module sets up FFI to use the H3 C library.
    module Base
      def self.extended(base)
        lib_path = File.expand_path(__dir__ + "/../../../ext/h3/src/lib")
        base.extend FFI::Library
        base.extend Gem::Deprecate
        base.include Structs
        base.include Types
        base.ffi_lib ["#{lib_path}/libh3.dylib", "#{lib_path}/libh3.so"]
        base.typedef :ulong_long, :h3_index
        base.typedef :int, :k_distance
      end

      def attach_predicate_function(name, *args)
        stripped_name = name.to_s.gsub("?", "")
        attach_function(stripped_name, *args).tap do
          rename_function stripped_name, name
        end
      end

      private

      def rename_function(from, to)
        alias_method to, from
        undef_method from
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
h3-3.7.2 lib/h3/bindings/base.rb
h3-3.7.1 lib/h3/bindings/base.rb
h3-3.6.2 lib/h3/bindings/base.rb