Re: Interactive interpreter in embedded application

Jan Wielemaker <[email protected]>
Newsgroups gmane.comp.ai.prolog.swi
Message-ID <[email protected]>
On 01/19/2014 11:46 AM, alu wrote:
> I have a C++ program that uses SWI-Prolog as a logic server via PlEngine. Now
> I'm wondering if it is possible to write a function, which behaves like the
> interactive interpreter command line. 
> 
> This function would receive a string (command line input) and return a
> string (command line output as a response to input). 
> *int PlCall(const char *goal)* seems to do the trick (input-wise), but I
> need something for the output.

You need to rebind the I/O streams and start a thread.  This is done in
src/pl-ntmain.c for the swipl-win.exe console on Windows.  If Qt is an
option
for you, Carlo Capelli has great stuff for you.

> This way it would be possible to have the interpreter in a GUI program (e.g.
> as a dock widget). Would be great for debugging and manipulation of an
> otherwise integrated Prolog system. 

Another alternative is to do

	PlCall("prolog_server(4000, [])");

that creates a telnet server on port 4000.  Then do

	% telnet localhost 4000
	Trying 127.0.0.1...
	Connected to localhost.
	Escape character is '^]'.
	Welcome to the SWI-Prolog server on thread client@localhost

	1 ?-

Be careful about your security!  I.e., only run this in a properly secured
environment.

	Enjoy --- Jan
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.