https://github.com/shinmera/cocoas
A toolkit library to help deal with CoreFoundation, Cocoa, and objc
https://github.com/shinmera/cocoas
Last synced: 17 days ago
JSON representation
A toolkit library to help deal with CoreFoundation, Cocoa, and objc
- Host: GitHub
- URL: https://github.com/shinmera/cocoas
- Owner: Shinmera
- Created: 2024-03-18T22:45:44.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-04-06T16:16:43.000Z (about 1 year ago)
- Last Synced: 2024-05-02T01:48:35.096Z (about 1 year ago)
- Language: Common Lisp
- Homepage: https://shinmera.github.io/cocoas/
- Size: 51.8 KB
- Stars: 7
- Watchers: 3
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.mess
Awesome Lists containing this project
- trackawesomelist - cocoas (⭐11) - A toolkit library to help deal with CoreFoundation, Cocoa, and objc. zlib. (Recently Updated / [May 09, 2025](/content/2025/05/09/README.md))
README
# About Cocoas
This is a small toolkit library to help deal with Apple's CoreFoundation, Cocoa, and Objective C interfaces.## How To
The library exposes the additional cffi types ``nsstring``, ``cfstring``, ``cfnumber``, ``cfset``, ``cfarray``, and ``cfdictionary`` to allow convenient translation between the respective Lisp representation of these types and the ObjC/CoreFoundation representation. You can use them like you would any other CFFI type.You can also define convenient Lisp function wrappers for static methods and instance methods, using ``define-objcfun`` and ``define-objcmethod`` respectively, using similar syntax to ``cffi:defcfun``:
:: common lisp
(cocoas:define-objcfun "NSAlert" alloc :pointer)
; [NSAlert alloc] => (nsalert-alloc)(cocoas:define-objcmethod init :pointer)
; [obj init] => (init obj)(cocoas:define-objcmethod run-modal :uint)
; [obj runModal] => (run-modal obj)(cocoas:define-objcmethod ((setf informative-text) "setInformativeText:") NIL
(text cocoas:nsstring))
; [obj setInformativeText: [NSString stringWithUTF8String: text]] => (setf (informative-text obj) text)
::To handle object cleanup and initialisation, there's ``with-main-loop``, ``with-objects``, and ``with-foundation-objects``.
:: common lisp
(cocoas:with-main-loop ()
(cocoas:with-objects ((window (init (nsalert-alloc))))
(setf (informative-text window) "Hello!")
(prog1 (run-modal window)
(loop while (cocoas:process-event)))))
::The library also installs a standard uncaught exception handler that translates and re-signals any ``NSException`` as a ``foundation-error`` so the errors can be dealt with Lisp-side.