[SWI-Prolog] Possible to register a foreign function dynamically?



Hello,

I am writing a Python package to interface SWI-Prolog's foreign
language API. The package uses SWI-Prolog as a shared library;
currently I can query it using PL_open_query just fine, the package is
at (for interested people):
http://code.google.com/p/pyswip

I've converted atom_checksum example at:
http://gollem.science.uva.nl/SWI-Prolog/Manual/foreigninclude.html to
Python, there's no problem in the initialization, and
PL_register_foreign works somehow , but when I run a query such as `X
is 10, atom_checksum(X, Y)`, i get a "ERROR: atom_checksum/2: Caught
signal 11 (segv)".

Here's my question: Is it possible to register a foreign function
dynamically without requiring a compilation step? I ask this because
all the examples I've found about it requires to have a function
called `install` which is calling `PL_register_foreign`.

Here's the Python code, I've changed `atom_checksum` so it always
returns false (the longer version is also problematic).

# ...
def atom_checksum(a0, arity, context):
return False

funtype = CFUNCTYPE(foreign_t, term_t, c_int, c_void_p)
PL_register_foreign("atom_checksum", 2, funtype(atom_checksum),
PL_FA_VARARGS)
list( prolog.query("X is 10, atom_checksum(X, Y)",
catcherrors=False) )

Thanks,

Yuce Tekol

.



Relevant Pages