[Openmcl-devel] @metaclass type definition

Paul Krueger plkrueger at comcast.net
Mon Apr 27 14:11:02 PDT 2009


Thanks, next time I'll look in the mail archive first.

If you're changing the examples, there are other small errors in this  
load nibfile example. The text leading up to the final version uses  
the constant "#&NSTopLevelObjects" instead of  
"#&NSNibTopLevelObjects" (although that is corrected in the final  
version of the code). And the function load-nibfile as shown in the  
example and in the example file ".../ccl/examples/cocoa/nib-loading/ 
load-nibfile.lisp" will not work as given. The object/key pairs passed  
to dictionaryWithObjectsAndKeys: must be null-terminated or you get an  
objective C runtime exception. I don't know if this is a result of  
changes made in the objective C methods since this was written or  
something else, but a version that works for me and is a bit safer is:

(defun load-nibfile (nib-path)
   (let* ((app (#/sharedApplication ns:ns-application))
          (app-zone (#/zone app))
          (nib-name (%make-nsstring (namestring nib-path)))
          (objects-array (#/arrayWithCapacity: ns:ns-mutable-array 16))
          (toplevel-objects (list))
          (dict (#/dictionaryWithObjectsAndKeys: ns:ns-mutable- 
dictionary
                 app #@"NSNibOwner"
                 objects-array #&NSNibTopLevelObjects
                 (%null-ptr)))
          (result (#/loadNibFile:externalNameTable:withZone: ns:ns- 
bundle
                                                             nib-name
                                                             dict
                                                             app-zone)))
     (when result
       (dotimes (i (#/count objects-array))
         (setf toplevel-objects
               (cons (#/objectAtIndex: objects-array i)
                     toplevel-objects))))
     (#/release nib-name)
     (#/release dict)
     (#/release objects-array)
     (values toplevel-objects result)))


On Apr 27, 2009, at 12:22 PM, R. Matthew Emerson wrote:

> Instead of (@class ns-mutable-array), you can just write ns:ns- 
> mutable-array, e.g.,
>
> (let* ((my-array (#/arrayWithCapacity: ns:ns-mutable-array 10)))
>   (...))
>
> See also:
> http://clozure.com/pipermail/openmcl-devel/2009-March/009009.html
>
> This needs to be fixed, obviously, but the @class thing is sort of  
> obsolete usage, so nobody's really taken a look.  I will see about  
> updating the example as soon as I can.
>
>
> On Apr 27, 2009, at 12:31 PM, Paul Krueger wrote:
>
>> I recently upgraded to: Clozure Common Lisp Version 1.3-r11966M   
>> (DarwinPPC32).
>>
>> I'm trying to run through the NIB loading examples as described in  
>> the file: ".../ccl/examples/cocoa/nib-loading/HOWTO.html". I did  
>> NOT try these on any previous release. Part of one of the examples  
>> does the following while in the ccl package:
>>
>> ? (setf *my-dict* (#/dictionaryWithObject:forKey: (@class ns- 
>> mutable-dictionary) *my-app* #@"NSNibOwner"))
>> When I do this I get the following:
>> > Error: Unknown type specifier: (@METACLASS "NSMutableDictionary")
>> > While executing: %%TYPEP, in process Listener(6).
>> Investigating further I did:
>> ? (macroexpand-1 '(@class ns-mutable-dictionary))
>> (THE (@METACLASS "NSMutableDictionary") (%OBJC-CLASS-CLASSPTR  
>> #S(OBJC-CLASS-DESCRIPTOR :NAME "NSMutableDictionary" :CLASSPTR  
>> #<OBJC:OBJC-CLASS NS:NS-MUTABLE-DICTIONARY (#xA015289C)>)))
>> T
>> So clearly the class was found and it's the @METACLASS type  
>> assertion that is causing the problem (just as the first error  
>> message said). I just bypassed the type declaration and got the  
>> example to work just fine.
>> The @class macro seems to be used in several places, so I hunted  
>> all over to see if I could discover how (@metaclass  ...) should  
>> have been turned into a valid type specifier, but couldn't find it.  
>> The closest I came was the function "get-objc-class-from- 
>> declaration" which as near as I can tell is only called in one  
>> place that didn't seem to be relevant to all the different ways  
>> that @class is used, but maybe I missed something there.
>> Can anyone clarify for me whether the example should have worked as  
>> written and if so what might be wrong? How does the @class macro  
>> defined in objc-runtime.lisp ever work?
>>
>> Thanks, Paul
>> _______________________________________________
>> Openmcl-devel mailing list
>> Openmcl-devel at clozure.com
>> http://clozure.com/mailman/listinfo/openmcl-devel
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.clozure.com/pipermail/openmcl-devel/attachments/20090427/e601e120/attachment.htm>


More information about the Openmcl-devel mailing list