From c31e45dda43e1bf10e66a724cb90d51cd6cfaa26 Mon Sep 17 00:00:00 2001 From: Matthias Benkard Date: Mon, 13 Aug 2007 13:59:04 +0200 Subject: Add a SELECTOR function and use coerced selectors in Objective C code rather than strings. darcs-hash:d10f9eafc3b21bfcfc027a263e8cee007155b89c --- Lisp/libobjcl.lisp | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) (limited to 'Lisp/libobjcl.lisp') 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 *) ;=> # + + (selector 'selph) ; error + + (selector \"stringWithCString:encoding:\") + ;=> # + + (selector '(:string-with-c-string :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. -- cgit v1.2.3