Skip to content

Instantly share code, notes, and snippets.

@vindarel
Created April 23, 2021 09:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vindarel/608e4b65dedb0169f7c1569dcaebd83d to your computer and use it in GitHub Desktop.
Save vindarel/608e4b65dedb0169f7c1569dcaebd83d to your computer and use it in GitHub Desktop.
How to build native Cocoa GUIs with Common Lisp (Clozure)

Historically, Clozure CL Objective-C bridge has been the best tool for this. On macOS CCL comes with a set of interfaces to Cocoa and some other OS frameworks that allow one to write native Cocoa applications in Common Lisp, with all the attendant advantages that provides. The Objective-C bridge is even pretty good at catching ObjC errors and turning them into Lisp errors, so one can have an iterative REPL-based development cycle for a macOS GUI application. Furthermore, the ObjC bridge can take Lisp representations of ObjC objects in a saved image and revive those objects--CCL provides tools to use his feature to build deployable GUI applications.

The problem is that the Objective-C bridge and the associated Cocoa interfaces have bit-rotted and no longer work portably on recent versions of macOS. A Lisp image saved using an older version of CCL used to reliably work on newer macOS versions. But now the images only seem to work reliably on the exact same macOS version, and often break even on minor revisions of the OS. Another problem is that the ObjC interfaces that come with CCL are very outdated now, and either reflect old versions of frameworks or lack newer frameworks (such as SceneKit) altogether. The transition to Apple Silicon has just compounded these problems: these isn't an Arm64 port of CCL, and the Intel version doesn't work quite right under Rosetta.

The only one of these problems I have some kind of solution for is that of building newer interfaces: over the last couple of years I've been tinkering off-and-on to extend the experimental command line tool that generates CCL's FFI interfaces so that it can read recent macOS framework headers. The code is not pretty but it works well enough to build working interfaces to newer frameworks like SceneKit. I've managed to use the resulting interfaces to write a few neat demos using CCL, such as an interactive cel-shaded version of the Utah teapot. But I don't believe the demos are portable: although I haven't checked, I suspect they will run on macOS 10.14 with CCL 1.12 only.

https://www.reddit.com/r/lisp/comments/mt6o0c/creating_apps_on_macos_for_free/guzpktn/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment