Changeset 15476


Ignore:
Timestamp:
Oct 9, 2012, 7:46:00 PM (8 years ago)
Author:
rme
Message:

Crude support for declaring that Objective-C classes implement
formal protocols.

Example:

(defclass some-objc-class (ns:ns-object)

((slot1 :accessor slot1 :foreign-type :id))
(:metaclass ns:+ns-object)
(:objc-protocols "NSTextInput" "NSCopying"))

See ticket:453.

Location:
trunk/source/objc-bridge
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/source/objc-bridge/objc-clos.lisp

    r14290 r15476  
    770770  (apply #'shared-initialize instance nil initargs))
    771771
    772 (defmethod initialize-instance :after ((class objc:objc-class) &key name &allow-other-keys)
     772(defmethod initialize-instance :after ((class objc:objc-class)
     773                                       &key name objc-protocols
     774                                         &allow-other-keys)
    773775  (unless (slot-value class 'foreign)
    774776    #-(or apple-objc-2.0 cocotron-objc)
     
    779781    (%add-objc-class class)
    780782    (setf (find-class name) class)
     783    (dolist (name objc-protocols)
     784      (let ((p (%get-objc-protocol (objc-class-name-string name))))
     785        (%add-objc-protocol class p)))
    781786    (ensure-dealloc-method-for-class class)))
    782787
  • trunk/source/objc-bridge/objc-runtime.lisp

    r15327 r15476  
    9999(defun lookup-objc-protocol (name)
    100100  (values (gethash name *objc-protocols*)))
     101
     102;;; I'm not sure we still need to avoid #_objc_getProtocol.
     103(defun %get-objc-protocol (name)
     104  (let ((p (lookup-objc-protocol name)))
     105    (if p
     106      (objc-protocol-address p)
     107      (error "No Objective-C protocol named ~s" name))))
     108
     109(defun %add-objc-protocol (class protocol)
     110  (when (= (#_class_addProtocol class protocol) #$YES)
     111    protocol))
    101112
    102113(defun ensure-objc-classptr-resolved (classptr)
Note: See TracChangeset for help on using the changeset viewer.