class SWIPL::PrologFrame
Public Class Methods
new( frame_id )
click to toggle source
# File lib/swipl/prologframe.rb, line 4 def initialize( frame_id ) @frame_id = frame_id end
on( &block )
click to toggle source
# File lib/swipl/prologframe.rb, line 24 def self.on( &block ) frame = self.open begin block.call( frame ) ensure frame.close end end
open()
click to toggle source
Opens a foreign frame
# File lib/swipl/prologframe.rb, line 16 def self.open frame_id = CFFI.PL_open_foreign_frame if frame_id == PL_FALSE raise "failed to open frame" end PrologFrame.new( frame_id ) end
Public Instance Methods
atom_from_string( string )
click to toggle source
# File lib/swipl/prologframe.rb, line 50 def atom_from_string( string ) atom_ptr = FFI::MemoryPointer.from_string( string.to_s ) atom_term = CFFI.PL_new_term_ref if CFFI.PL_chars_to_term( atom_ptr, atom_term ) == 0 raise "failed to create atom from terms" end Term.new( atom_term ) end
close()
click to toggle source
# File lib/swipl/prologframe.rb, line 8 def close result = CFFI.PL_discard_foreign_frame( @frame_id ) if result == PL_FALSE raise "Failed to close frame" end end
ref()
click to toggle source
# File lib/swipl/prologframe.rb, line 46 def ref refs(1)[0] end
refs( count )
click to toggle source
allocates teh number of terms and returns an array of those terms
NOTE: SWI requires continous terms from time to time (ie: PL_open_query)
# File lib/swipl/prologframe.rb, line 36 def refs( count ) return [] if count == 0 base = CFFI.PL_new_term_refs( count ) #TODO: Verify the result of the query (0..(count-1)).map do |index| Term.new( base + index ) end end