an example; update change log
parent
bbf871e28a
commit
1167a22e10
|
|
@ -48,6 +48,15 @@ this is lexicographic order, and for words, this compares word names.</li>
|
|||
<li>C library interface:
|
||||
|
||||
<ul>
|
||||
<li>Support for binding to Objective C libraries is now included.
|
||||
<ul>
|
||||
<li>Normal usage of Objective C classes and methods is done using the <code>OBJC-CLASS:</code>
|
||||
and <code>OBJC-MESSAGE:</code> parsing words. See the example in
|
||||
<code>examples/cocoa-speech.factor</code>.</li>
|
||||
<li>Objective C runtime introspection functions and structures are defined in the
|
||||
<code>objective-c</code> vocabulary.</li>
|
||||
</ul>
|
||||
</li>
|
||||
<li>Added a pair of words for between Factor strings and C strings, <code>alien>string</code> and <code>string>alien</code>.
|
||||
</li>
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,36 @@
|
|||
! Copyright (C) 2006 Slava Pestov
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
|
||||
! This example requires Mac OS X. It has only been tested on
|
||||
! 10.4. It must be run from a Factor runtime linked against the
|
||||
! Cocoa library; you can obtain one with the 'macosx-sdl' target
|
||||
! in the Makefile.
|
||||
|
||||
IN: cocoa-speech
|
||||
USING: alien compiler kernel objective-c sequences words ;
|
||||
|
||||
! Define classes and messages
|
||||
OBJC-MESSAGE: id alloc ;
|
||||
OBJC-CLASS: NSString
|
||||
: NSASCIIStringEncoding 1 ; inline
|
||||
OBJC-MESSAGE: id initWithCString: char* encoding: uint ;
|
||||
OBJC-CLASS: NSSpeechSynthesizer
|
||||
OBJC-MESSAGE: id initWithVoice: id ;
|
||||
OBJC-MESSAGE: bool startSpeakingString: id ;
|
||||
|
||||
! A utility
|
||||
: <NSString> ( string -- alien )
|
||||
NSString [alloc]
|
||||
swap NSASCIIStringEncoding [initWithCString:encoding:] ;
|
||||
|
||||
! As usual, alien invoke words need to be compiled
|
||||
"cocoa-speech" words [ try-compile ] each
|
||||
|
||||
! A utility
|
||||
: <NSSpeechSynthesizer> ( voice -- synth )
|
||||
NSSpeechSynthesizer [alloc] swap [initWithVoice:] ;
|
||||
|
||||
! Call the TTS API
|
||||
f <NSSpeechSynthesizer>
|
||||
"Hello from Factor" <NSString>
|
||||
[startSpeakingString:]
|
||||
|
|
@ -2,6 +2,8 @@
|
|||
! See http://factorcode.org/license.txt for BSD license.
|
||||
IN: objective-c
|
||||
|
||||
LIBRARY: objc
|
||||
|
||||
TYPEDEF: void* SEL
|
||||
|
||||
TYPEDEF: void* id
|
||||
|
|
|
|||
Loading…
Reference in New Issue