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
: init-cocoa
"NSObject" define-objc-class
"NSString" define-objc-class
"NSSpeechSynthesizer" define-objc-class ; parsing
init-cocoa
USING: objc-NSString objc-NSObject objc-NSSpeechSynthesizer ;
: NSASCIIStringEncoding 1 ; inline
! A utility
: <NSString> ( string -- alien )
NSString [alloc]
swap NSASCIIStringEncoding [initWithCString:encoding:] ;
! A utility
: <NSSpeechSynthesizer> ( voice -- synth )
NSSpeechSynthesizer [alloc] swap [initWithVoice:] ;
@ -33,7 +25,7 @@ USING: objc-NSString objc-NSObject objc-NSSpeechSynthesizer ;
! Call the TTS API
: speech-test
f <NSSpeechSynthesizer>
"Hello from Factor" <NSString>
"Hello from Factor" <CFString>
[startSpeakingString:] ;
! 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* CFBundleGetFunctionPointerForName ( void* bundle, void* functionName ) ; compiled
FUNCTION: bool CFBundleLoadExecutable ( void* bundle ) ; compiled
FUNCTION: void CFRelease ( void* cf ) ; compiled
@ -51,7 +49,7 @@ FUNCTION: void CFRelease ( void* cf ) ; compiled
CFBundleLoadExecutable drop
{
"NSObject" "NSWindow"
"NSURLRequest" "NSApplication" "%NSURL"
"NSURLRequest" "NSApplication"
"WebView" "WebFrame"
} [ dup define-objc-class "objc-" swap append use+ ] each ;
parsing

View File

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

View File

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

View File

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

View File

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

View File

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