From b4d918caa529470b218d0acec3d644fee2337cac Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Thu, 2 Oct 2008 07:10:22 -0500 Subject: [PATCH] Some minor new features for Cocoa binding --- basis/cocoa/application/application.factor | 2 +- basis/cocoa/cocoa-docs.factor | 9 ++++++++- basis/cocoa/cocoa.factor | 12 +++++++++++- basis/cocoa/messages/messages-docs.factor | 6 +----- basis/cocoa/messages/messages.factor | 3 ++- basis/cocoa/standalone/standalone.factor | 12 ++++++++++++ 6 files changed, 35 insertions(+), 9 deletions(-) create mode 100644 basis/cocoa/standalone/standalone.factor diff --git a/basis/cocoa/application/application.factor b/basis/cocoa/application/application.factor index a28952ea33..065a4abc5a 100755 --- a/basis/cocoa/application/application.factor +++ b/basis/cocoa/application/application.factor @@ -30,7 +30,7 @@ IN: cocoa.application FUNCTION: void NSBeep ( ) ; : with-cocoa ( quot -- ) - [ NSApp drop call ] with-autorelease-pool ; + [ NSApp drop call ] with-autorelease-pool ; inline : next-event ( app -- event ) 0 f CFRunLoopDefaultMode 1 diff --git a/basis/cocoa/cocoa-docs.factor b/basis/cocoa/cocoa-docs.factor index a971288251..dd8d331b35 100644 --- a/basis/cocoa/cocoa-docs.factor +++ b/basis/cocoa/cocoa-docs.factor @@ -16,9 +16,16 @@ HELP: SUPER-> { send super-send POSTPONE: -> POSTPONE: SUPER-> } related-words +HELP: IMPORT: +{ $syntax "IMPORT: name" } +{ $description "Makes an Objective C class available for use." } +{ $examples + { $code "IMPORT: QTMovie" "QTMovie \"My Movie.mov\" f -> movieWithFile:error:" } +} ; + ARTICLE: "objc-calling" "Calling Objective C code" "Before an Objective C class can be used, it must be imported; by default, a small set of common classes are imported automatically, but additional classes can be imported as needed." -{ $subsection import-objc-class } +{ $subsection POSTPONE: IMPORT: } "Every imported Objective C class has as corresponding class word in the " { $vocab-link "cocoa.classes" } " vocabulary. Class words push the class object in the stack, allowing class methods to be invoked." $nl "Messages can be sent to classes and instances using a pair of parsing words:" diff --git a/basis/cocoa/cocoa.factor b/basis/cocoa/cocoa.factor index 744d577c0d..ab86796236 100755 --- a/basis/cocoa/cocoa.factor +++ b/basis/cocoa/cocoa.factor @@ -3,7 +3,7 @@ USING: compiler io kernel cocoa.runtime cocoa.subclassing cocoa.messages cocoa.types sequences words vocabs parser core-foundation namespaces assocs hashtables compiler.units -lexer ; +lexer init ; IN: cocoa : (remember-send) ( selector variable -- ) @@ -27,6 +27,16 @@ SYMBOL: super-sent-messages scan dup remember-super-send parsed \ super-send parsed ; parsing +SYMBOL: frameworks + +frameworks global [ V{ } clone or ] change-at + +[ frameworks get [ load-framework ] each ] "cocoa.messages" add-init-hook + +: FRAMEWORK: scan [ load-framework ] [ frameworks get push ] bi ; parsing + +: IMPORT: scan [ ] import-objc-class ; parsing + "Compiling Objective C bridge..." print "cocoa.classes" create-vocab drop diff --git a/basis/cocoa/messages/messages-docs.factor b/basis/cocoa/messages/messages-docs.factor index f78981c923..9b5e3fdfd9 100644 --- a/basis/cocoa/messages/messages-docs.factor +++ b/basis/cocoa/messages/messages-docs.factor @@ -32,11 +32,7 @@ HELP: alien>objc-types HELP: import-objc-class { $values { "name" string } { "quot" "a quotation with stack effect " { $snippet "( -- )" } } } -{ $description "If a class named " { $snippet "name" } " is already known to the Objective C interface, does nothing. Otherwise, first calls the quotation. The quotation should make the class available to the Objective C runtime if necessary, either by loading a framework or defining it directly. After the quotation returns, this word makes the class available to Factor programs by importing methods and creating a class word the class object in the " { $vocab-link "cocoa.classes" } " vocabulary." } -{ $notes "In most cases, the quotation should be " { $link f } "." } -{ $examples - { $code "\"QTMovie\" f import-objc-class" "QTMovie \"My Movie.mov\" f -> movieWithFile:error:" } -} ; +{ $description "If a class named " { $snippet "name" } " is already known to the Objective C interface, does nothing. Otherwise, first calls the quotation. The quotation should make the class available to the Objective C runtime if necessary, either by loading a framework or defining it directly. After the quotation returns, this word makes the class available to Factor programs by importing methods and creating a class word the class object in the " { $vocab-link "cocoa.classes" } " vocabulary." } ; HELP: root-class { $values { "class" alien } { "root" alien } } diff --git a/basis/cocoa/messages/messages.factor b/basis/cocoa/messages/messages.factor index 7977485b02..09601ef8cc 100755 --- a/basis/cocoa/messages/messages.factor +++ b/basis/cocoa/messages/messages.factor @@ -4,7 +4,8 @@ USING: accessors alien alien.c-types alien.strings arrays assocs combinators compiler kernel math namespaces make parser prettyprint prettyprint.sections quotations sequences strings words cocoa.runtime io macros memoize debugger -io.encodings.ascii effects compiler.generator libc libc.private ; +io.encodings.ascii effects compiler.generator libc libc.private +parser lexer init core-foundation ; IN: cocoa.messages : make-sender ( method function -- quot ) diff --git a/basis/cocoa/standalone/standalone.factor b/basis/cocoa/standalone/standalone.factor new file mode 100644 index 0000000000..528736f172 --- /dev/null +++ b/basis/cocoa/standalone/standalone.factor @@ -0,0 +1,12 @@ +! Copyright (C) 2008 Slava Pestov. +! See http://factorcode.org/license.txt for BSD license. +USING: kernel cocoa.nibs cocoa.application cocoa ; +IN: cocoa.standalone + +: cocoa-app ( quot -- ) + [ + "MiniFactor.nib" load-nib + call + finish-launching + NSApp -> run + ] with-cocoa ; inline