Re: External Predicates & Embedding

From: Joachim Schimpf <j.schimpf_at_icparc.ic.ac.uk>
Date: Tue 09 Aug 2005 06:25:15 PM GMT
Message-ID: <42F8F50B.9020304@icparc.ic.ac.uk>
Simon Christensen wrote:
>...
> The problem that arises is that I can find no way of convincing ECLiPSe 
> to actually register my external predicate. The usual (and as far as I 
> can see, the only documented) way of using external predicates is to 
> compile the desired C functions into a shared library, load the library 
> into ECLiPSe and register the functions with ECLiPSe using external/2.
> 
> Unfortunately, what I know of shared libraries leads me to the 
> conclusion that this isn't going to be possible for my application, as 
> the predicate in question needs to be able to communicate with other 
> parts of my program. I've tried using external/2 to link a predicate to 
> the desired function, however my ECLiPSe embedding doesn't like this, 
> coughing up an "External function does not exist" error.

On some operating systems, the external/2 predicate seems to be
unable to find the symbols of the embedding host program (I just
tried, it works on Solaris, but for instance not on Linux).

Fortunately, there is an (accidentally undocumented) C function
which does the equivalent of external/2:
int ec_external(dident predicate, int(*fct)(), dident module)
the return code is PSUCCEED or PFAIL.

Instead of calling from ECLiPSe
     external(change_node_colour/1, p_change_node_colour)
call from C
     ec_external(ec_did("change_node_colour",1),
	 p_change_node_colour, ec_did("eclipse",0))

If you are happy to have the predicate in the 'eclipse' module,
you can do this call immediately after ec_init(). If you want it
in a module that is created only later during compilation of your
Eclipse code, you have to call ec_external after compiling the
Eclipse code, and you will probably need an external/1 forward
declararion in the Eclipse source.


-- 
  Joachim Schimpf              /             phone: +44 20 7594 8187
  IC-Parc                     /      mailto:J.Schimpf@imperial.ac.uk
  Imperial College London    /    http://www.icparc.ic.ac.uk/eclipse
Received on Tue Aug 09 19:29:05 2005

This archive was generated by hypermail 2.1.8 : Wed 16 Nov 2005 06:07:39 PM GMT GMT