Module: Upl::Inter
- Defined in:
- lib/upl/inter.rb
Overview
Inter operation
Defined Under Namespace
Classes: Agc
Class Method Summary collapse
- .attach_atom_hook ⇒ Object
-
.each_of_list(lst_term, &blk) ⇒ Object
lst_term is a Term, or a Fiddle::Pointer to term_t yield term_t items of the lst_term.
-
.register_mcall_predicate ⇒ Object
call any method on any object, from prolog.
-
.term_t_of(term_or_ptr) ⇒ Object
Try Term, then Fiddle::Pointer, then to_term_t.
Class Method Details
.attach_atom_hook ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/upl/inter.rb', line 69 module_function def attach_atom_hook @atom_hook = atom_hook = Fiddle::Closure::BlockCaller.new Fiddle::TYPE_INT, [Fiddle::TYPE_VOIDP] do |atom_t| atom = Upl::Atom.new atom_t p atom_t: atom_t.to_i, atom: atom if atom.to_obj_id obj = atom.to_ruby p obj: obj, dereg: (Agc.instance.deregister obj) end # FALSE here will prevent garbage collection Upl::Extern::TRUE end # NOTENOTE this must NOT be garbage-collected, otherwise the callback to it will fail. @atom_hook_fn = Fiddle::Function.new atom_hook, atom_hook.args, atom_hook.ctype # returns old fn ptr Upl::Extern.PL_agc_hook @atom_hook_fn end |
.each_of_list(lst_term, &blk) ⇒ Object
lst_term is a Term, or a Fiddle::Pointer to term_t yield term_t items of the lst_term
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/upl/inter.rb', line 32 def self.each_of_list lst_term, &blk return enum_for __method__, lst_term unless block_given? lst_term = Inter.term_t_of lst_term while Extern::PL_get_nil(lst_term) != 1 # not end of list res = Extern::PL_get_list \ lst_term, (head_t = Extern.PL_new_term_ref), (rst_t = Extern.PL_new_term_ref) break unless res == 1 yield head_t lst_term = rst_t end end |
.register_mcall_predicate ⇒ Object
call any method on any object, from prolog
21 22 23 24 25 |
# File 'lib/upl/inter.rb', line 21 def self.register_mcall_predicate Upl::Foreign.register_semidet :mcall do |obj,meth,val| val === obj.send(meth) end end |
.term_t_of(term_or_ptr) ⇒ Object
Try Term, then Fiddle::Pointer, then to_term_t. Return a term_t pointer
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/upl/inter.rb', line 9 def self.term_t_of term_or_ptr case term_or_ptr when Term term_or_ptr.term_t when Fiddle::Pointer term_or_ptr else term_or_ptr.to_term_t end end |