Module: SWIPL::CFFI

Extended by:
FFI::Library
Defined in:
lib/swipl/cffi.rb

Class Method Summary collapse

Class Method Details

.bootstrapObject



36
37
38
39
40
41
42
# File 'lib/swipl/cffi.rb', line 36

def self.bootstrap
  lib_path = ENV["SWI_LIB"]
  raise "SWI_LIB not set and loader for your platform." unless lib_path

  @swipl_lib = lib_path
  self.load( lib_path )
end

.import_symbolsObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/swipl/cffi.rb', line 7

def self.import_symbols
  attach_function :PL_open_foreign_frame, [], :ulong
  attach_function :PL_discard_foreign_frame, [:ulong], :int

  # Warning: the following method repeatedly failed
  attach_function :PL_atom_chars, [:ulong], :pointer

  attach_function :PL_call, [:ulong, :pointer], :int
  attach_function :PL_chars_to_term, [:pointer, :ulong], :int
  attach_function :PL_close_query, [:ulong], :void
  attach_function :PL_get_atom_chars, [:ulong, :pointer], :int
  attach_function :PL_initialise, [:int, :pointer], :int
  attach_function :PL_is_atom, [:ulong], :int
  attach_function :PL_is_ground, [:ulong], :int
  attach_function :PL_new_atom, [:pointer], :ulong
  attach_function :PL_new_term_ref, [], :ulong
  attach_function :PL_new_term_refs, [:int], :ulong
  attach_function :PL_next_solution, [:ulong], :int
  attach_function :PL_open_query, [:pointer, :int, :ulong, :ulong], :ulong
  attach_function :PL_predicate, [:pointer, :int, :pointer], :ulong
  attach_function :PL_thread_self, [], :int
  attach_function :PL_unify, [ :ulong, :ulong ], :int
end

.initObject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/swipl/cffi.rb', line 44

def self.init
  return if @is_initialized
  self.bootstrap unless @ffi_libs

  libptr = ::FFI::MemoryPointer.from_string( @swipl_lib )
  plargv = ::FFI::MemoryPointer.new( :pointer, 1 )
  plargv.write_pointer( libptr )

  value = PL_initialise( 1, plargv )
  if value != 1
    raise "SWI failed to initialize"
  end

  @is_initialized = true
end

.load(libraries) ⇒ Object



31
32
33
34
# File 'lib/swipl/cffi.rb', line 31

def self.load( libraries )
  ffi_lib libraries
  self.import_symbols
end