diff options
author | Matthias Benkard <code@mail.matthias.benkard.de> | 2007-08-13 13:59:04 +0200 |
---|---|---|
committer | Matthias Benkard <code@mail.matthias.benkard.de> | 2007-08-13 13:59:04 +0200 |
commit | c31e45dda43e1bf10e66a724cb90d51cd6cfaa26 (patch) | |
tree | 407813141cf00e4a505c6b30afbe14c47fe52797 /Lisp/libobjcl.lisp | |
parent | c5fce012e0a31684eb96ee8770c6b4fb229d3e60 (diff) |
Add a SELECTOR function and use coerced selectors in Objective C code rather than strings.
darcs-hash:d10f9eafc3b21bfcfc027a263e8cee007155b89c
Diffstat (limited to 'Lisp/libobjcl.lisp')
-rw-r--r-- | Lisp/libobjcl.lisp | 51 |
1 files changed, 50 insertions, 1 deletions
diff --git a/Lisp/libobjcl.lisp b/Lisp/libobjcl.lisp index 00560fe..a713c8e 100644 --- a/Lisp/libobjcl.lisp +++ b/Lisp/libobjcl.lisp @@ -70,7 +70,7 @@ objects or classes, let alone send messages to them. (defcfun ("objcl_invoke_method" %objcl-invoke-method) obj-data (receiver obj-data) - (method-name :string) + (method-selector obj-data) (argc :int) &rest) @@ -183,6 +183,55 @@ conventional case for namespace identifiers in Objective C." (foreign-string-to-lisp/dealloc (%objcl-selector-name obj-data)))) +(defun selector (designator) + "Convert an object into a selector. + +## Arguments and Values: + +*designator* --- a *selector designator*. + + +## Description: + +*selector-designator* must be a valid *selector designator*, that is: +either a __selector__ object or one of a **symbol**, a **string**, or a +**list** of **symbol**s representing a __selector__. + +If *selector-designator* is a **string** or a **list** of **symbol**s, +__find-selector__ is called and the value returned, except that if +__find-selector__ returns __nil__, an **error** is **signal**ed. + +If *selector-designator* is a single **symbol**, it is treated as if it +were a **list** whose **car** is the **symbol** and whose **cdr** is +__nil__. + +If *selector-designator* is a __selector__, it is simply returned. + + +## Examples: + + (selector \"self\") ;=> #<SELECTOR `self'> + (selector '(self)) ;=> #<SELECTOR `self'> + (selector 'self) ;=> #<SELECTOR `self'> + (selector *) ;=> #<SELECTOR `self'> + + (selector 'selph) ; error + + (selector \"stringWithCString:encoding:\") + ;=> #<SELECTOR `stringWithCString:encoding:'> + + (selector '(:string-with-c-string :encoding)) + ;=> #<SELECTOR `stringWithCString:encoding:'>" + + (ctypecase designator + (selector designator) + (symbol (selector (list designator))) + ((or string list) + (or (find-selector designator) + (error "Could not find the selector designated by ~S." + designator))))) + + (defun find-selector (selector-name) "Retrieve a method selector by name. |