1 ! Copyright (C) 2006 Slava Pestov
2 ! See http://factorcode.org/license.txt for BSD license.
4 USING: alien arrays errors hashtables kernel math memory
9 FUNCTION: void* CFArrayCreateMutable ( void* allocator, CFIndex capacity, void* callbacks ) ;
11 FUNCTION: void* CFArrayGetValueAtIndex ( void* array, CFIndex idx ) ;
13 FUNCTION: void CFArraySetValueAtIndex ( void* array, CFIndex index, void* value ) ;
15 FUNCTION: CFIndex CFArrayGetCount ( void* array ) ;
17 : kCFURLPOSIXPathStyle 0 ;
19 FUNCTION: void* CFURLCreateWithFileSystemPath ( void* allocator, void* filePath, int pathStyle, bool isDirectory ) ;
21 FUNCTION: void* CFURLCreateWithString ( void* allocator, void* string, void* base ) ;
23 FUNCTION: void* CFURLCopyFileSystemPath ( void* url, int pathStyle ) ;
25 FUNCTION: void* CFStringCreateWithCharacters ( void* allocator, ushort* cStr, CFIndex numChars ) ;
27 FUNCTION: CFIndex CFStringGetLength ( void* theString ) ;
29 FUNCTION: void CFStringGetCharacters ( void* theString, CFIndex start, CFIndex length, void* buffer ) ;
31 FUNCTION: CFIndex CFStringGetLength ( void* string ) ;
33 FUNCTION: void* CFBundleCreate ( void* allocator, void* bundleURL ) ;
35 FUNCTION: bool CFBundleLoadExecutable ( void* bundle ) ;
37 FUNCTION: void CFRelease ( void* cf ) ;
39 : CF>array ( alien -- array )
40 dup CFArrayGetCount [ CFArrayGetValueAtIndex ] map-with ;
42 : <CFArray> ( seq -- array )
43 [ f swap length f CFArrayCreateMutable ] keep
45 [ >r dupd r> CFArraySetValueAtIndex ] 2each ;
47 : <CFString> ( string -- cf )
48 f swap dup length CFStringCreateWithCharacters ;
50 : CF>string ( string -- string )
51 dup CFStringGetLength 1+ "ushort" <c-array> [
52 >r 0 over CFStringGetLength r> CFStringGetCharacters
53 ] keep alien>u16-string ;
55 : CF>string-array ( alien -- seq )
56 CF>array [ CF>string ] map ;
58 : <CFFileSystemURL> ( string dir? -- cf )
59 >r <CFString> f over kCFURLPOSIXPathStyle
60 r> CFURLCreateWithFileSystemPath swap CFRelease ;
62 : <CFURL> ( string -- cf )
64 [ f swap f CFURLCreateWithString ] keep
67 : <CFBundle> ( string -- cf )
72 : load-framework ( name -- )
74 CFBundleLoadExecutable drop
76 "Cannot load bundled named " swap append throw