[Openmcl-devel] What's the minimal way to start using the ObjectiveC bridge?

Paul Krueger plkrueger at comcast.net
Mon Apr 28 10:31:23 PDT 2014


Did you mean "setObject:forKey:" ?  There is no standard addObject:forKey: objective-C method. You also need to understand the correct syntax for calling obj-c methods in CCL:

? (defun lisp-to-temp-nsstring (string)
  ;; creates a string that is not owned by caller
  ;; so no release is necessary
  (with-encoded-cstrs :utf-8 ((s string))
    (#/stringWithUTF8String: ns:ns-string s)))
LISP-TO-TEMP-NSSTRING
? (setf key (lisp-to-temp-nsstring "key string"))
#<NS-MUTABLE-STRING "key string" (#x117690)>
? (setf obj (make-instance ns:ns-object))
#<NS-OBJECT [uninitialized] (#x21074380)>
? (setf dict (make-instance ns:ns-mutable-dictionary))
#<NS-MUTABLE-DICTIONARY {
} (#x121D60)>
? (#/setObject:forKey: dict obj key)
NIL
? (describe dict)
#<NS-MUTABLE-DICTIONARY {
    "key string" = "<NSObject: 0x21074380>";
} (#x121D60)>
Class: #<OBJC:OBJC-CLASS NS:NS-MUTABLE-DICTIONARY (#x7FFF7AF09618)>
Wrapper: #<CCL::CLASS-WRAPPER NS:NS-MUTABLE-DICTIONARY #x302000C665CD>
Instance slots
NS:ISA: #<NS-OBJECT __NSDictionaryM (#x7FFF7AF09578)>
? (#/objectForKey: dict key)
#<NS-OBJECT [uninitialized] (#x21074380)>
? (eql obj *)
T
? 

You could use standard #/allocate and #/init calls instead of make-instance calls. This just demonstrates how obj-c has been integrated into CLOS.

On Apr 28, 2014, at 11:07 AM, Leo Liu <sdl.web at gmail.com> wrote:

> On 2014-04-28 10:04 -0500, Paul Krueger wrote:
>> It's not entirely clear to me what you are trying to do, but perhaps 
>> 
>> (require :objc-support)
>> 
>> is what you are looking for. This will make most objective-c
>> functionality available to you in a command line listener. This will
>> let you create and initialize objective-C objects, but there is no
>> cocoa application started in such an environment unless you create one
>> yourself and doing that correctly can be complex. You would also need
>> to explicitly handle all memory management for any objective-c objects
>> you create in this environment.
> 
> Thanks for this. My CCL 1.9 is from Mac Homebrew and I keep getting
> segfaults:
> 
> Welcome to Clozure Common Lisp Version 1.9-r15759  (DarwinX8664)!
> ? (require :objc-support)
> :OBJC-SUPPORT
> ("OBJC-PACKAGE" "SEQUENCE-UTILS" "NAME-TRANSLATION" "OBJC-CLOS" "OBJC-RUNTIME" "BRIDGE" "OBJC-SUPPORT")
> ? (objc:@selector #/addObject:forKey:)
> Trace/BPT trap: 5
> 
> Leo
> 
> _______________________________________________
> Openmcl-devel mailing list
> Openmcl-devel at clozure.com
> http://lists.clozure.com/mailman/listinfo/openmcl-devel




More information about the Openmcl-devel mailing list