From: Sohail Somani
Subject: CFFI + Slime + std::cout
Date: 
Message-ID: <NJi9k.680$1o6.297@edtnps83>
Hey,

How can I get Slime to relay the output (through std::cout) of a C++ 
function called through CFFI through to the REPL?

I see the desired output in the *inferior-lisp* buffer but I want it to 
show up in the *slime-repl* buffer.

Thanks

Sohail

From: Stephen Compall
Subject: Re: CFFI + Slime + std::cout
Date: 
Message-ID: <m2tzfd2r07.fsf@nocandysw.com>
Sohail Somani <······@taggedtype.net> writes:
> How can I get Slime to relay the output (through std::cout) of a C++
> function called through CFFI through to the REPL?

This is really a CFFI question, and you may wish to send further
followups to the CFFI list instead.  Create a C++ shared library with a
few elements, then load and initialize it using CFFI:

1. A subclass of std::ostream that holds a void(*)(const char*) as an
   instance variable, forwarding all output received to that function.

2. A function like

   extern "C" void init_mylispcout (void (*writer) (const char*));

   that replaces std::cout with an instance of #1.  I forget whether C++
   allows you to change std::cout.

3. A CFFI callback in Lisp to be passed to #2, that writes the output on
   some Lisp stream.

4. A CFFI defcfun on #2.

-- 
But you know how reluctant paranormal phenomena are to reveal
themselves when skeptics are present. --Robert Sheaffer, SkI 9/2003
From: Sohail Somani
Subject: Re: CFFI + Slime + std::cout
Date: 
Message-ID: <48671548.5060205@taggedtype.net>
Stephen Compall wrote:
> Sohail Somani <······@taggedtype.net> writes:
>> How can I get Slime to relay the output (through std::cout) of a C++
>> function called through CFFI through to the REPL?
> 
> This is really a CFFI question, and you may wish to send further
> followups to the CFFI list instead.  

Not sure if it is a CFFI question or a Slime question. Probably not a 
ANSI CL question though :-)

 > Create a C++ shared library with a
> few elements, then load and initialize it using CFFI:

Yes, this is an option. For now I've just stuck to executing my program 
in the console and going back to the REPL when I need the interactivity. 
Works ok so far but I should not get distracted by nice-to-haves :-)

Thanks!

Sohail