Contents (package MULK.OBJECTIVE-CL)


Macro DEFINE-OBJECTIVE-C-METHOD

Purpose:

Define a new Objective-C method.

Syntax:

define-objective-c-method name &rest args

args ::= {qualifier}* lambda-list [[{declaration}* | docstring]] {form}*

Arguments and Values:

name --- a symbol.

qualifier --- a method qualifier.

return-type --- a typespec.

lambda-list --- a modified lambda list.

docstring --- a string (not evaluated).

declaration --- a local declaration (not evaluated).

forms --- an implicit progn.

Description:

define-objective-c-generic-function is like defgeneric except in the following aspects:

  1. name is immediately replaced by a symbol interned in package objective-c-methods.

  2. The default value for the :generic-function-class option is objective-cl:objective-c-generic-function.

  3. The default value for the :method-class option is objective-cl:objective-c-method.

define-objective-c-generic-function recognises the same options as defgeneric, including :generic-function-class and :method-class.

The lexical environment of body is augmented to include the function super.

Example:

#.(enable-method-syntax)  
  
(define-objective-c-class ns::mlk-my-class (ns::ns-object)  
     ((foos :initargs :foos)  
      (foo-count :foreign-type :int)))  
  => NS::MLK-MY-CLASS  
  
(define-objective-c-generic-function #/foo:bar:stuff:do: (self y z a b))  
  => #<OBJECTIVE-C-GENERIC-FUNCTION OBJECTIVE-C-METHODS::|foo:bar:stuff:do:| (0)>  
  
(define-objective-c-method #/foo:bar:stuff:do: :int  
    ((self ns::mlk-my-class) (y :int) z a (b ns::ns-number))  
  (format t "Hello!  Z and A are ~A and~  
              ~&~A, respectively.~  
              ~&Have a nice day." z a)  
  (+ y 20))  
  => #<OBJECTIVE-C-METHOD  
       OBJECTIVE-C-METHODS::|foo:bar:stuff:do:|  
       ((EQL NS:MLK-MY-CLASS) NS:MLK-MY-CLASS T T T NS:NS-NUMBER) {CE8E531}>  
  
(#/foo:bar:stuff:do: (#/new (find-objc-class 'ns::mlk-my-class))  
                     100  
                     30  
                     "FOO!"  
                     5)  
  => Output:  
       Hello!  Z and A are #<NS:NS-INT-NUMBER `30' {82F1DC0}> and  
       #<NS:MLK-LISP-STRING `FOO!' {82F2190}>, respectively.  
       Have a nice day.  
  => 120  
  
#.(disable-method-syntax)  
 

Note 1:

It is not generally possible to define methods after a class has already been registered with the Objective-C runtime. The latter inevitably happens when Objective-CL first sees an instance of the class.

Note 2:

If you do not call define-objective-c-generic-function before using define-objective-c-method, it will be called implicitly by the latter. There is nothing wrong with relying on this; in fact, if you do not want to set any options for the generic function, your code will probably seem less cramped if you leave the redundant define-objective-c-generic-function calls out.

Note 3:

It is customary to use the #/ notation enabled by enable-method-syntax to write method names for define-objective-c-generic-function.

Note 4:

Do not call call-next-method in the body of an objective-c-method. Its behaviour is quite different from super, ill-defined, and probably not desirable anyway.

Use super instead.

See also:

define-objective-c-generic-function, define-objective-c-class, super