[Ecls-list] CLOS streams

Julian St. der_julian at web.de
Thu Jun 26 15:45:12 UTC 2003


Hello,

having the ability to create own streams proves to be really useful for using ECL as a plugin. But I wonder what the right way to this it (especially what methods I have to provide, currently I just grep'ed thorugh the ECL sources to see where ECL_CLOS_STREAMS takes effect). I tried it the following way ( %print is the only function that gets called. It emits a single line and changes to the next ).

The implementation as it is seen below works despite of two issues: 

1) I get the following warnings:

;;; Warning: STREAM-CLOSE is being redefined.
;;; Warning: STREAM-INPUT-P is being redefined.
;;; Warning: STREAM-OUTPUT-P is being redefined.
;;; Warning: STREAM-WRITE-CHAR is being redefined.
;;; Warning: STREAM-FORCE-OUTPUT is being redefined.
;;; Warning: STREAM-CLEAR-OUTPUT is being redefined.

2) I think there too many empty lines written. Looks strange sometimes:

(from terminal)
> (describe 'cons)

...
-----------------------------------------------------------------------
CONS                                                         [Function]
Function in COMMON-LISP package:
...


(from X-Chat with my redirection)
-----------------------------------------------------------------------  CONS 
                                                              [Function] Function in COMMON-LISP package:        



Regards,
Julian

Code follows:

;; Getting *standard-output* redirected to X-Chat.

(defclass xchat-stream
    ()
  ((lbuffer :accessor xchat-stream-buffer
	    :initform (make-array  0 :adjustable t :fill-pointer t
				   :element-type 'character)))
  (:documentation "A stream directed to X-Chat"))

(defmethod stream-close ((stream xchat-stream))
  (error "Cannot close ~S." stream))

(defmethod stream-input-p ((stream xchat-stream))
  nil)

(defmethod stream-output-p ((stream xchat-stream))
  t)

(defmethod stream-flush-buffer ((stream xchat-stream))
  (if (not (zerop (length (xchat-stream-buffer stream)))) ; FIXME: This removes a lot of strange empty lines...
      (%print (xchat-stream-buffer stream)))
  (stream-clear-output stream))
    
(defmethod stream-write-char ((stream xchat-stream) char)
  (if (char= char #\Newline)
      (stream-flush-buffer stream)
      (vector-push-extend char (xchat-stream-buffer stream))))

(defmethod stream-force-output ((stream xchat-stream))
  (stream-flush-buffer stream))

(defmethod stream-clear-output ((stream xchat-stream))
  (setf (xchat-stream-buffer stream) (make-array  0 :adjustable t :fill-pointer t
   						  :element-type 'character)))

(setq *standard-output* (make-instance 'xchat-stream))

-- 
Support strong cryptography.

Key ID     : D65B2AB5 
Fingerprint: FA38 DCD3 00EC 97B8 6DD8  D7CC 35D8 8D0E D65B 2AB5
Key server : pgp.mit.edu

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 187 bytes
Desc: not available
URL: <https://mailman.common-lisp.net/pipermail/ecl-devel/attachments/20030626/d0b8132b/attachment.sig>


More information about the ecl-devel mailing list