[Openmcl-devel] Three questions

Ron Garret ron at awun.net
Sat Feb 9 00:54:04 UTC 2008


On Feb 8, 2008, at 3:24 PM, Gary Byers wrote:

>
>
> On Fri, 8 Feb 2008, Ron Garret wrote:
>
>> 1.  Is there a way to tell when a window has been closed?  Sometimes
>> the window seems to turn into a bogus obj-C object, but sometimes it
>> doesn't.  And even when it does, TYPE-OF still returns ns:ns-window:
>>
>> ? w
>> #<Bogus ObjC Object #x14901E00>
>> ? (type-of w)
>> NS:NS-WINDOW
>> ?
>>
>> but doing anything else with the window (like asking for its
>> contentView) crashes CCL.
>
> ? (defvar *o* (make-instance 'ns:ns-object))
> *O*
> ? (#/retainCount *o*)
> 1
> ? (#/release *o*)
> NIL
> ? *o*
> #<Bogus ObjC Object #x12CE7730>
>
> ObjC objects aren't real, first-class lisp objects after all (because
> it's possible for them to be "deallocated" when their (ObjC) reference
> counts become 0.
>
> My usual argument is that while this is bad (and it'd be good to
> integrate the lisp and ObjC GCs so that this kind of thing can't
> happen), it' not as bad in practice as it is in theory (because
> many of the objects that one deals with from the lisp side of
> things are relatively long-lived (windows, views) and it's rare
> to hold lisp references to those things.  At least the first
> part of that is likely true.)

Yes, but windows are a notable exception because one often wishes to  
retain pointers to them (so you can draw in them for example) but they  
can (and in the normal course of events often do) become deallocated  
asynchronously as a result of a user's actions, to wit, clicking on  
the "close" button.


>
>
>>
>> 2.  Why doesn't this work:
>>
>> (objc:load-framework "Webkit" :webkit)
>> (setf w (make-window 500 300))
>> (setf v (make-instance 'ns:web-view))
>> (#/setContentView: w v)
>> (setf f (#/mainFrame v))
>> (#/loadRequest: f
>>  (#/requestWithURL: ns:ns-url-request
>>    (#/URLWithString: ns:ns-url #@"http://www.google.com/")))
>
> In what thread does it not work (e.g., how is this code different
> from the webkit example ?

I tried it from a cocoa listener.  The webkit example (using  
performSelectorOnMainThread:withObject:waitUntilDone:) works.

> It also doesn't have any opportunity to process the URL request.

Oh, so *that's* what the docs meant when they said, "the process of  
loading a web page is asynchronous and complicated".

:-)

Thanks!

rg




More information about the Openmcl-devel mailing list