LispWorks Objective-C and Cocoa Interface User Guide and Reference Manual > 3 The Cocoa Interface > 3.4 How to run Cocoa on its own

NextPrevUpTopContentsIndex

3.4.1 LispWorks as a Cocoa application

The following startup function can be used to make LispWorks run as a Cocoa application. Typically, before calling "run" you would create an application delegate with a method on applicationDidFinishLaunching: to initialize the application's windows.

(defun init-function ()
  (mp:initialize-multiprocessing
   "main thread"
   '()
   #'(lambda ()
       (objc:ensure-objc-initialized
        :modules
        '("/System/Library/Frameworks/Foundation.framework/Versions/C/Foundation"
          "/System/Library/Frameworks/Cocoa.framework/Versions/A/Cocoa"))
       (objc:with-autorelease-pool ()
         (let ((app (objc:invoke "NSApplication"
                                 "sharedApplication")))
           (objc:invoke app "run"))))))

To use this, a bundle must be created, calling init-function on startup. For example, the following build script will create lw-cocoa-app.app

(in-package "CL-USER")
(load-all-patches)
(example-compile-file
 "configuration/macos-application-bundle.lisp" :load t)
(save-image (when (save-argument-real-p)
              (write-macos-application-bundle "lw-cocoa-app"))
            :restart-function 'init-function)

See "Saving a LispWorks image" in the LispWorks User Guide and Reference Manual for information on using a build script to create a new LispWorks image.


LispWorks Objective-C and Cocoa Interface User Guide and Reference Manual - 22 Dec 2009

NextPrevUpTopContentsIndex