On Fri, Jan 15, 2010 at 9:05 PM, Alan Ruttenberg
<alanruttenberg@...> wrote:
> Thanks Alessio.
>
> How about the other patches?
>
> http://sourceforge.net/mailarchive/message.php?msg_name=29af5e2d1001141029ved6e76ay532cd0f120614e2f%40mail.gmail.com
>
> Fixes the print-object method for close methods specialized on java classes
>
> http://sourceforge.net/mailarchive/message.php?msg_name=29af5e2d1001141243s5ff7264fg8538d4054448879%40mail.gmail.com
>
> Defines a base method for printing java objects, replicating the
> behavior of what is currently defined in the java code, and modifies
> output-ugly-object so that it gets called.
>
> Would it be possible to integrate these as well?
[R12377] and [R12379] should do it; let me know if they work for you.
A couple of notes:
for method specialized on Java classes, I made what I believe to be
the right thing: have the symbol slot of JavaClass initialized with an
uninterned symbol named like the class, so that it's printed correctly
by the existing code. Examples:
CL-USER(1): (defmethod foo ((obj (jclass "java.lang.Object"))) obj)
#<STANDARD-METHOD FOO (#:|java.lang.Object|) {C95DAA}>
CL-USER(2): (mop::%class-name (class-of (jnew "java.lang.String")))
#:|java.lang.String|
for print-object on java objects, I just made it call %write-to-string
on the object, which calls the Java writeToString(), so it's only
implemented once. Apparently changing output-ugly-object wasn't
necessary, but if you find out it is, let me know.
Additionally, I have a local patch to make jclass work with custom
classloaders, if you're interested. I prefer to be cautious with this
one and not to commit it immediately; I need to properly test it.
Bye, Ale
[R12377] http://trac.common-lisp.net/armedbear/changeset/12377
[R12379] http://trac.common-lisp.net/armedbear/changeset/12379
> Thanks,
> Alan
>
> On Thu, Jan 14, 2010 at 5:11 PM, Alessio Stalla <alessiostalla@...> wrote:
>> On Thu, Jan 14, 2010 at 10:29 PM, Alan Ruttenberg
>> <alanruttenberg@...> wrote:
>>> Well, not quite.
>>>
>>> Also, slime calls sys::frame-to-string, which doesn't respect java
>>> object's print-object method.
>>> This is inside java code and I don't know how to properly fix that.
>>> I'm patching as:
>>>
>>> (advise sys::frame-to-string
>>> (if (typep (car arglist) 'system::lisp-stack-frame)
>>> (prin1-to-string
>>> (sys::frame-to-list (car arglist)))
>>> (:do-it)
>>> )
>>> :when :around
>>> :name :freedom)
>>>
>>> but would appreciate if someone could do the right thing.
>>
>> You should find that on trunk: I actually called prin1-to-string from
>> Java; I don't think that should cause any problems, but if someone has
>> objections, let me know.
>>
>> Alessio
>>
>>> -Alan
>>>
>>>
>>> On Thu, Jan 14, 2010 at 3:43 PM, Alan Ruttenberg
>>> <alanruttenberg@...> wrote:
>>>> On Thu, Jan 14, 2010 at 1:29 PM, Alan Ruttenberg
>>>> <alanruttenberg@...> wrote:
>>>>> Now to find out why slime isn't using #'print-object ...
>>>>>
>>>>> -Alan
>>>>>
>>>>
>>>> That would be because print isn't calling print-object for java objects.
>>>>
>>>> (in-package #:system)
>>>>
>>>> ;; define the default method for java objects
>>>> (defmethod print-object ((obj java::java-object) stream)
>>>> (print-unreadable-object (obj stream :identity t)
>>>> (let ((tostring (jcall "toString" obj)))
>>>> (if (> (length tostring) 32)
>>>> (format stream "~a ~a..." (java::jclass-name (java::jobject-class
>>>> obj)) (subseq tostring 0 32) stream)
>>>> (format stream "~a ~a" (java::jclass-name (java::jobject-class obj))
>>>> tostring stream)))))
>>>>
>>>>
>>>> ;; modify so that print-object is called on java objects too.
>>>>
>>>> (defun output-ugly-object (object stream)
>>>> (cond ((consp object)
>>>> (output-list object stream))
>>>> ((and (vectorp object)
>>>> (not (stringp object))
>>>> (not (bit-vector-p object)))
>>>> (output-vector object stream))
>>>> ((structure-object-p object)
>>>> (cond
>>>> ((and (null *print-readably*)
>>>> *print-level*
>>>> (>= *current-print-level* *print-level*))
>>>> (write-char #\# stream))
>>>> (t
>>>> (print-object object stream))))
>>>> ((standard-object-p object)
>>>> (print-object object stream))
>>>> ((java::java-object-p object)
>>>> (print-object object stream))
>>>> ((xp::xp-structure-p stream)
>>>> (let ((s (sys::%write-to-string object)))
>>>> (xp::write-string++ s stream 0 (length s))))
>>>> (t
>>>> (%output-object object stream))))
>>>>
>>>
>>
>
|