Document cocoa-app combinator

db4
Slava Pestov 2008-10-02 10:53:12 -05:00
parent dbae275dc2
commit efe0bf2ecd
2 changed files with 17 additions and 3 deletions

View File

@ -26,6 +26,10 @@ HELP: with-cocoa
{ $values { "quot" quotation } } { $values { "quot" quotation } }
{ $description "Sets up an autorelease pool, initializes the " { $snippet "NSApplication" } " singleton, and calls the quotation." } ; { $description "Sets up an autorelease pool, initializes the " { $snippet "NSApplication" } " singleton, and calls the quotation." } ;
HELP: cocoa-app
{ $values { "quot" quotation } }
{ $description "Initializes Cocoa, calls the quotation, and starts the Cocoa event loop." } ;
HELP: do-event HELP: do-event
{ $values { "app" "an " { $snippet "NSApplication" } } { "?" "a boolean" } } { $values { "app" "an " { $snippet "NSApplication" } } { "?" "a boolean" } }
{ $description "Processes a pending event in the queue, if any, returning a boolean indicating if there was one. Does not block." } ; { $description "Processes a pending event in the queue, if any, returning a boolean indicating if there was one. Does not block." } ;
@ -46,13 +50,16 @@ HELP: objc-error
{ $error-description "Thrown by the Objective C runtime when an error occurs, for example, sending a message to an object with an unrecognized selector." } ; { $error-description "Thrown by the Objective C runtime when an error occurs, for example, sending a message to an object with an unrecognized selector." } ;
ARTICLE: "cocoa-application-utils" "Cocoa application utilities" ARTICLE: "cocoa-application-utils" "Cocoa application utilities"
"Utilities:"
{ $subsection NSApp } { $subsection NSApp }
{ $subsection with-autorelease-pool }
{ $subsection with-cocoa }
{ $subsection do-event } { $subsection do-event }
{ $subsection add-observer } { $subsection add-observer }
{ $subsection remove-observer } { $subsection remove-observer }
{ $subsection install-delegate } ; { $subsection install-delegate }
"Combinators:"
{ $subsection cocoa-app }
{ $subsection with-autorelease-pool }
{ $subsection with-cocoa } ;
IN: cocoa.application IN: cocoa.application
ABOUT: "cocoa-application-utils" ABOUT: "cocoa-application-utils"

View File

@ -50,6 +50,13 @@ FUNCTION: void NSBeep ( ) ;
: finish-launching ( -- ) NSApp -> finishLaunching ; : finish-launching ( -- ) NSApp -> finishLaunching ;
: cocoa-app ( quot -- )
[
call
finish-launching
NSApp -> run
] with-cocoa ; inline
: install-delegate ( receiver delegate -- ) : install-delegate ( receiver delegate -- )
-> alloc -> init -> setDelegate: ; -> alloc -> init -> setDelegate: ;