summaryrefslogtreecommitdiff
path: root/Lisp/libobjcl.lisp
diff options
context:
space:
mode:
authorMatthias Benkard <code@mail.matthias.benkard.de>2007-08-04 17:27:49 +0200
committerMatthias Benkard <code@mail.matthias.benkard.de>2007-08-04 17:27:49 +0200
commit4bf7ff0fac043bbe1516e00fdd3567ed38fe6ff4 (patch)
tree060b10832dba766ec739c40a5262651bc5613aa2 /Lisp/libobjcl.lisp
parent0b07278c11c0ecb073356b15f1ed5e8781583d0c (diff)
Define an external interface, properly document FIND-OBJC-CLASS.
darcs-hash:2e4424a65b72a13e3cfa26d07dce945bc35ba8e1
Diffstat (limited to 'Lisp/libobjcl.lisp')
-rw-r--r--Lisp/libobjcl.lisp68
1 files changed, 65 insertions, 3 deletions
diff --git a/Lisp/libobjcl.lisp b/Lisp/libobjcl.lisp
index d735773..a7171b4 100644
--- a/Lisp/libobjcl.lisp
+++ b/Lisp/libobjcl.lisp
@@ -7,8 +7,10 @@
(use-foreign-library libobjcl)
-(defcfun "objcl_initialise_runtime" :void)
-(defcfun "objcl_shutdown_runtime" :void)
+(defcfun ("objcl_initialise_runtime" initialise-runtime) :void)
+
+(defcfun ("objcl_shutdown_runtime" shutdown-runtime) :void)
+
(defcfun ("objcl_invoke_instance_method"
%objcl-invoke-instance-method) obj-data
(receiver obj-data)
@@ -30,7 +32,67 @@
(class obj-data))
-(defun objcl-find-class (class-name)
+(defun symbol->objc-class-name (symbol)
+ (let ((components (split-sequence #\- (symbol-name symbol)
+ :remove-empty-subseqs t)))
+ (reduce #'(lambda (x y) (concatenate 'string x y))
+ (mapcar #'(lambda (x)
+ (concatenate 'string
+ (string (char x 0))
+ (string-downcase (subseq x 1))))
+ (subseq components 1))
+ :initial-value (concatenate 'string
+ (string (char (first components) 0))
+ (string-upcase
+ (subseq (first components) 1))))))
+
+
+(defun find-objc-class (class-name)
+ "Retrieve an Objective C class by name.
+
+CLASS-NAME: a symbol or a string.
+
+Returns: an OBJC-CLASS object representing the class whose name is
+CLASS-NAME.
+
+
+If CLASS-NAME is a symbol which does not contain a hyphen, its symbol
+name is converted to lower case except for the first letter, which is
+left intact, and the resulting string used as if directly given as an
+argument to FIND-OBJC-CLASS.
+
+If CLASS-NAME is a symbol which containts a hyphen, its symbol name is
+split into components seperated by hyphens and each component is
+converted into a string according to the following rules:
+
+ 1. The first component is fully converted to upper case except for its
+ first letter, which is left intact.
+
+ 2. Any additional components have all of their letters converted to
+ lower case, except for their first letters, which are left intact.
+
+After this, the components are concatenated in order and the resulting
+string used as if directly given as an argument to FIND-OBJC-CLASS.
+
+Examples:
+
+ (find-objc-class \"NSObject\") ;=> #<OBJC-CLASS NSObject>
+ (find-objc-class 'ns-object) ;=> #<OBJC-CLASS NSObject>
+ (find-objc-class 'nsobject) ;=> NIL
+
+Rationale:
+
+The first component of an Objective C class name is conventionally
+thought of as a namespace identifier. It is therefore sensible to
+expect it to be converted to upper case by default, which is the
+conventional case for namespace identifiers in Objective C."
+
+ (typecase class-name
+ (string (find-objc-class-by-name class-name))
+ (symbol (find-objc-class-by-name (symbol->objc-class-name class-name)))))
+
+
+(defun find-objc-class-by-name (class-name)
(let ((obj-data (%objcl-find-class class-name)))
(prog1
(if (null-pointer-p (foreign-slot-value