[Ecls-list] Embedding ECL inside a containing C++ program.

Juan Jose Garcia-Ripoll jlr at mpq.mpg.de
Tue Aug 20 02:19:03 UTC 2002


Hi Andrew,

I am sorry for the delay on the answer.

On Saturday 17 August 2002 18:21, Andrew Topp wrote:
> The project I'm working on is Universal Corporation
> (http://sourceforge.net/projects/unicorp).
>
> I'm attempting to embed the ECL Lisp interpreter
> within UniCorp as its scripting engine, console
> command interpreter and UI manager, among other things [...]

Great to hear it.

> I'd like the input from the graphical console to be
> fed into the Lisp top-level. I'd like the output to be
> displayed on the graphical console. Looking over the
> guts of print.d and file.d doesn't seem to offer much
> help.

What I am going to suggest is untested, but it has been implemented in ECL 
since the very first versions (It belongs to Beppe). In ECL you can write to 
any object which supports the methods

{&clSstream_write_char, "STREAM-WRITE-CHAR", CL_ORDINARY},
{&clSstream_write_string, "STREAM-WRITE-STRING", CL_ORDINARY},
{&clSstream_fresh_line, "STREAM-FRESH-LINE", CL_ORDINARY},
{&clSstream_clear_output, "STREAM-CLEAR-OUTPUT", CL_ORDINARY},
{&clSstream_force_output, "STREAM-FORCE-OUTPUT", CL_ORDINARY},

and you can read to from any object which supports the methods

{&clSstream_read_line, "STREAM-READ-LINE", CL_ORDINARY},
{&clSstream_read_char, "STREAM-READ-CHAR", CL_ORDINARY},
{&clSstream_unread_char, "STREAM-UNREAD-CHAR", CL_ORDINARY},
{&clSstream_peek_char, "STREAM-PEEK-CHAR", CL_ORDINARY},
{&clSstream_listen, "STREAM-LISTEN", CL_ORDINARY},
{&clSstream_clear_input, "STREAM-CLEAR-INPUT", CL_ORDINARY},

See the code in print.d and read.d to find out how it works. It is pretty easy 
and the important points are enclosed within pairs of #ifdef CLOS...#endif

As far as I recall, these objects need not be descendent of the class STREAM. 
Only the methods should be there. Perhaps you can define these methods to 
call your console reading/writing routines.

The other possibility which comes to my mind is that you define two STRING 
streams. One for input, one for output. Then you should have an entry point 
to the Lisp code, that you call whenever an event happens. This routine would 
perform output by writing to the STRING stream, and on exit your graphical 
toplevel could collect the output and actually present it.

> I've hacked up my CVS version slightly and
> incorporated it into the UC tree (mainly
> Makefile/configure modifications to work with the
> Makefile-only UC build system. Still working on Mingw
> combatability (sic)).

I would like to learn about these changes. Mingw was always on my mind as a 
possible target, but I would not now how to go from the unix scripts to 
Makefiles.

Juanjo

-- 
Max-Planck-Institut fuer Quantenoptik	+49/089/32905-127
Hans-Kopfermann-Str. 1, D-85748		www.arrakis.es/~worm
Garching b. Muenchen, Germany		worm at arrakis.es






More information about the ecl-devel mailing list