git.fiddlerwoaroof.com
Raw Blame History
* Intro
  
CCL and LispWorks and other implementations have their own bridges to
the objective-c runtime.  This project is an attempt to create a
bridge that only uses CFFI so that arbitrary lisp implementations can
produce native mac GUIs.  In the long run, I hope to use this as the
basis for a new mac-native backend for McClim: but we'll see if that
ever happens.

For the time being, though, this only works on CCL and (sort-of) on
LispWorks: it works like 95% on SBCL, but there's some weird issue
that's preventing the window from showing. I hae not tested the code
on any other implementations, but doing so will require changing a
couple places in objc-runtime.lisp to inform the code about the new
lisp's ffi types.

* Installing

1. clone fwoar.lisputils from
   https://github.com/fiddlerwoaroof/fwoar.lisputils and put it
   somewhere quicklisp can find it (e.g. ~/quicklisp/local-projects)

2. Install rsvg-convert:
    #+BEGIN_SRC sh
brew install librsvg
    #+END_SRC
   
3. build + run the demo:
   #+BEGIN_SRC sh
make mkapp CCL=/path/to/ccl
open demo.app
   #+END_SRC

* Show me the code!
  
From demo-app.lisp:

#+BEGIN_SRC lisp
  (defun main ()
    (trivial-main-thread:with-body-in-main-thread (:blocking t)
      [#@NSAutoReleasePool @(new)]
      [#@NSApplication @(sharedApplication)]
      [objc-runtime::ns-app @(setActivationPolicy:) :int 0]

      (let ((app-delegate (objc-runtime::objc-allocate-class-pair
                           #@NSObject "AppDelegate" 0)))
        (objc-runtime::add-pointer-ivar app-delegate "window")
        (objc-runtime::add-pointer-ivar app-delegate "delegate"))

      (let* ((bundle [#@NSBundle @(mainBundle)])
             (nib [[#@NSNib @(alloc)] @(initWithNibNamed:bundle:)
                                      :pointer @"MainMenu"
                                      :pointer bundle]))
        (cffi:with-foreign-object (p :pointer)
          [nib @(instantiateWithOwner:topLevelObjects:)
               :pointer objc-runtime::ns-app
               :pointer p]))
      [objc-runtime::ns-app @(activateIgnoringOtherApps:) :boolean t]
      [objc-runtime::ns-app @(run)]))
#+END_SRC