Moving Cocoa bindings

slava 2006-02-10 01:34:49 +00:00
parent 44f2cc04ef
commit 21af22aa5b
8 changed files with 21 additions and 26 deletions

View File

@ -12,20 +12,12 @@ USING: alien compiler kernel objc sequences words ;
! Define classes and messages ! Define classes and messages
: init-cocoa : init-cocoa
"NSObject" define-objc-class "NSObject" define-objc-class
"NSString" define-objc-class
"NSSpeechSynthesizer" define-objc-class ; parsing "NSSpeechSynthesizer" define-objc-class ; parsing
init-cocoa init-cocoa
USING: objc-NSString objc-NSObject objc-NSSpeechSynthesizer ; USING: objc-NSString objc-NSObject objc-NSSpeechSynthesizer ;
: NSASCIIStringEncoding 1 ; inline
! A utility
: <NSString> ( string -- alien )
NSString [alloc]
swap NSASCIIStringEncoding [initWithCString:encoding:] ;
! A utility ! A utility
: <NSSpeechSynthesizer> ( voice -- synth ) : <NSSpeechSynthesizer> ( voice -- synth )
NSSpeechSynthesizer [alloc] swap [initWithVoice:] ; NSSpeechSynthesizer [alloc] swap [initWithVoice:] ;
@ -33,7 +25,7 @@ USING: objc-NSString objc-NSObject objc-NSSpeechSynthesizer ;
! Call the TTS API ! Call the TTS API
: speech-test : speech-test
f <NSSpeechSynthesizer> f <NSSpeechSynthesizer>
"Hello from Factor" <NSString> "Hello from Factor" <CFString>
[startSpeakingString:] ; [startSpeakingString:] ;
! As usual, alien invoke words need to be compiled ! As usual, alien invoke words need to be compiled

View File

@ -21,8 +21,6 @@ FUNCTION: void* CFStringCreateWithCString ( void* allocator, char* cStr, int enc
FUNCTION: void* CFBundleCreate ( void* allocator, void* bundleURL ) ; compiled FUNCTION: void* CFBundleCreate ( void* allocator, void* bundleURL ) ; compiled
FUNCTION: void* CFBundleGetFunctionPointerForName ( void* bundle, void* functionName ) ; compiled
FUNCTION: bool CFBundleLoadExecutable ( void* bundle ) ; compiled FUNCTION: bool CFBundleLoadExecutable ( void* bundle ) ; compiled
FUNCTION: void CFRelease ( void* cf ) ; compiled FUNCTION: void CFRelease ( void* cf ) ; compiled
@ -51,7 +49,7 @@ FUNCTION: void CFRelease ( void* cf ) ; compiled
CFBundleLoadExecutable drop CFBundleLoadExecutable drop
{ {
"NSObject" "NSWindow" "NSObject" "NSWindow"
"NSURLRequest" "NSApplication" "%NSURL" "NSURLRequest" "NSApplication"
"WebView" "WebFrame" "WebView" "WebFrame"
} [ dup define-objc-class "objc-" swap append use+ ] each ; } [ dup define-objc-class "objc-" swap append use+ ] each ;
parsing parsing

View File

@ -26,7 +26,7 @@ math namespaces ;
[ set-alien-unsigned-8 ] "setter" set [ set-alien-unsigned-8 ] "setter" set
8 "width" set 8 "width" set
8 "align" set 8 "align" set
[ "box_unsinged_8" %box ] "boxer" set [ "box_unsigned_8" %box ] "boxer" set
[ "unbox_unsigned_8" %unbox ] "unboxer" set [ "unbox_unsigned_8" %unbox ] "unboxer" set
] "ulonglong" define-primitive-type ] "ulonglong" define-primitive-type

View File

@ -144,9 +144,6 @@ vectors words ;
"/library/alien/syntax.factor" "/library/alien/syntax.factor"
"/library/alien/malloc.factor" "/library/alien/malloc.factor"
"/library/alien/objective-c/runtime.factor"
"/library/alien/objective-c/utils.factor"
"/library/io/buffer.factor" "/library/io/buffer.factor"
"/library/cli.factor" "/library/cli.factor"

View File

@ -34,6 +34,10 @@ sequences sequences-internals words ;
"Initializing native I/O..." print flush "Initializing native I/O..." print flush
"native-io" get [ init-io ] when "native-io" get [ init-io ] when
os "macosx" = [
"/library/cocoa/load.factor" run-resource
] when
] when ] when
[ [
@ -48,7 +52,7 @@ H{ } clone crossref set
recrossref recrossref
"Setting the resource path..." print "Setting the resource path..." print
cwd global [ "resource-path" set ] bind cwd global "resource-path" set-global
[ compiled? ] word-subset length [ compiled? ] word-subset length
number>string write " compiled words" print number>string write " compiled words" print

View File

@ -1,8 +1,8 @@
! Copyright (C) 2006 Slava Pestov ! Copyright (C) 2006 Slava Pestov
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
IN: objc IN: objc
USING: alien arrays hashtables kernel lists math namespaces USING: alien arrays errors hashtables kernel lists math
parser sequences words ; namespaces parser sequences words ;
TUPLE: selector name object ; TUPLE: selector name object ;
@ -85,6 +85,7 @@ C: selector ( name -- sel ) [ set-selector-name ] keep ;
[ method-list>seq % (objc-methods) ] [ 2drop ] if* ; [ method-list>seq % (objc-methods) ] [ 2drop ] if* ;
: objc-methods ( class -- seq ) : objc-methods ( class -- seq )
[ "Null pointer passed to objc-methods" throw ] unless*
[ f <void*> (objc-methods) ] { } make ; [ f <void*> (objc-methods) ] { } make ;
: instance-methods ( classname -- seq ) : instance-methods ( classname -- seq )

View File

@ -29,9 +29,12 @@ sequences words ;
: try-compile ( word -- ) : try-compile ( word -- )
[ compile ] [ error. drop ] recover ; [ compile ] [ error. drop ] recover ;
: compile-all ( -- ) : compile-vocabs ( vocabs -- )
[ f "no-effect" set-word-prop ] each-word [ words ] map concat
[ try-compile ] each-word ; dup [ f "no-effect" set-word-prop ] each
[ try-compile ] each ;
: compile-all ( -- ) vocabs compile-vocabs ;
: recompile ( word -- ) dup update-xt compile ; : recompile ( word -- ) dup update-xt compile ;