Cocoa in Common Lisp
NOTE: currently, only tested on SBCL (2.5.10) on macOS (m1 air Sequoia 15.5 and m2 air Tahoe 26.2). cannot ensure and won’t provide support for other implementation or other platform (right now). But contributions are welcomed.
Coca is (or SHOULD BE) self-documented.
Load the system and use sly-describe-symbol or SLIME functions
to read the documentation of each symbol.
A few examples could be found under =examples= directory.
Loads coca/objc and use package :coca.objc (see objc/readme for details).
Load coca/frameworks will only loads
coca/frameworks/foundation and coca/frameworks/appkit.
ObjC bindings of Foundation Framework Access essential data types, collections, and operating-system services to define the base layer of functionality for your app. The Foundation framework provides a base layer of functionality for apps and frameworks, including data storage and persistence, text processing, date and time calculations, sorting and filtering, and networking. The classes, protocols, and data types defined by Foundation are used throughout the macOS, iOS, watchOS, and tvOS SDKs. see https://developer.apple.com/documentation/Foundation?language=objc
ObjC bindings of AppKit Framework Construct and manage a graphical, event-driven user interface for your macOS app. AppKit contains the objects you need to build the user interface for a macOS app. In addition to drawing windows, buttons, panels, and text fields, it handles all the event management and interaction between your app, people, and macOS. see https://developer.apple.com/documentation/AppKit?language=objc
ObjC bindings of Webkit Framework Integrate web content seamlessly into your app, and customize content interactions to meet your app's needs. Use the WebKit framework to integrate richly styled web content into your app's native content. WebKit offers a full browsing experience for your content, offering a platform-native view and supporting classes to: + Display rich web content using HTML, CSS, and JavaScript + Handle the incremental loading of page content + Display multiple MIME types and compound frame elements + Navigate between pages of content + Manage a forward-back list of recently visited pages For more information about WebKit, go to https://webkit.org. see https://developer.apple.com/documentation/WebKit?language=objc
Coca is distributed under the LLGPL (Lisp Lesser General Public
License). You are free to use Coca as a library within your commercial
Cocoa applications. However, I kindly ask that any improvements or
modifications to Coca itself remain open-sourced, so that the entire
community can benefit and Coca can continue to evolve through your
contributions.
- [ ] Cocoa examples (github:gammasoft71/Examples_Cocoa),
see examples/basic/readme.org
by the time it’s finished, Coca could be thought as mostly finished and ready for real productition codes
- [ ] Deploy,
expected to be
examples/deploy/readme.orgcurrently it’s possible to
save-lisp-and-die(withcoca-initto reset ObjC environment), but may not able to deliver to end user - [ ] Applications, expected to be under
applicationthose applications should only be experimental, not meant to be performance for actual productivity (just to proof that Coca could do so)
- [ ] Lem Coca Backend,
expected to be under
application/lemascoca/lemsubsystem - [ ] Nyxt Coca Backend,
expected to be under
application/nyxtascoca/nyxtsubsystem - [ ] CLIM Coca Backend,
expected to be under
application/climascoca/climsubsystem
- [ ] Lem Coca Backend,
expected to be under
If you just want to do some rapid prototyping or you need something
that are not provided with Coca currently, you can use functions
provided in Coca/ObjC to call ObjC methods directly:
For example:
[object SEL ...]could be written as(invoke object SEL ...)
Note that it’s also recommanded to load Coca/Frameworks system
(or at least Coca/Frameworks/Foundation) since it wrapps a lot
of ObjC method in the lispy style.
I wrote a helper script in devtools/parse-apple-docs.js, which
could be used to extract definitions from Apple’s documentation
website. It maynot always generate correct code so use it with
caution.
Style Guide:
define-objc-const: the const should be named like+const-name+Example:
+ns-foundation-version-number+
Values converting:
as-xxx: convert lisp values into ObjC formExample:
as-boolean: convert values as ObjC:boolas-ns-font:
decode-xxx: convert ObjC values into lisp valueby default,
define-objc-enumwill automatically generate decoder for enum numbers
Methods:
- use lisp methods rather than ObjC methods
Generic functions:
init: implementinitto set the logic of creating an ObjC objectxxxpandxxx-xxx-p: boolean test slots should have accessor function withp(lisp style) testing names
I cannot say that current Coca/ObjC is perfectly working.
The code and the performance should be more robust.
- Apple’s Documentation
- Cocoa examples (github:gammasoft71/Examples_Cocoa)
some of the examples are learnt from this repo
- Silicon.h (github:EimaKve/Silicon)
some of the examples are learnt from this repo
Below is the developping notes on my blog (mostly Chinese):