factor/library/cocoa/core-foundation.factor

67 lines
2.0 KiB
Factor
Raw Normal View History

2006-02-09 20:36:11 -05:00
! Copyright (C) 2006 Slava Pestov
! See http://factorcode.org/license.txt for BSD license.
IN: cocoa
2006-03-19 15:43:40 -05:00
USING: alien arrays errors hashtables kernel math memory
namespaces sequences ;
2006-02-09 22:11:22 -05:00
TYPEDEF: int CFIndex
2006-02-09 20:36:11 -05:00
! Core Foundation utilities -- will be moved elsewhere
: kCFURLPOSIXPathStyle 0 ;
2006-03-15 00:24:00 -05:00
: kCFStringEncodingMacRoman HEX: 0 ;
2006-03-14 21:09:25 -05:00
: kCFStringEncodingUnicode HEX: 100 ;
2006-02-09 20:36:11 -05:00
FUNCTION: void* CFURLCreateWithFileSystemPath ( void* allocator, void* filePath, int pathStyle, bool isDirectory ) ;
FUNCTION: void* CFURLCreateWithString ( void* allocator, void* string, void* base ) ;
2006-03-14 21:09:25 -05:00
FUNCTION: void* CFURLCopyFileSystemPath ( void* url, int pathStyle ) ;
2006-03-15 00:24:00 -05:00
FUNCTION: void* CFStringCreateWithCString ( void* allocator, char* cStr, int encoding ) ;
2006-02-09 20:36:11 -05:00
2006-02-09 22:11:22 -05:00
FUNCTION: CFIndex CFStringGetLength ( void* theString ) ;
2006-03-15 00:24:00 -05:00
FUNCTION: bool CFStringGetCString ( void* theString, void* buffer, CFIndex bufferSize, int encoding ) ;
FUNCTION: CFIndex CFStringGetLength ( void* string ) ;
2006-02-09 22:11:22 -05:00
2006-02-09 20:36:11 -05:00
FUNCTION: void* CFBundleCreate ( void* allocator, void* bundleURL ) ;
FUNCTION: bool CFBundleLoadExecutable ( void* bundle ) ;
FUNCTION: void CFRelease ( void* cf ) ;
: <CFString> ( string -- cf )
2006-03-15 00:24:00 -05:00
f swap kCFStringEncodingMacRoman CFStringCreateWithCString ;
2006-02-09 20:36:11 -05:00
2006-02-09 22:11:22 -05:00
: CF>string ( string -- string )
2006-03-15 00:24:00 -05:00
dup CFStringGetLength 1+ dup <byte-array> [
swap kCFStringEncodingMacRoman CFStringGetCString drop
] keep alien>string ;
2006-02-09 22:11:22 -05:00
2006-02-09 20:36:11 -05:00
: <CFFileSystemURL> ( string dir? -- cf )
>r <CFString> f over kCFURLPOSIXPathStyle
r> CFURLCreateWithFileSystemPath swap CFRelease ;
: <CFURL> ( string -- cf )
<CFString>
[ f swap f CFURLCreateWithString ] keep
CFRelease ;
: <CFBundle> ( string -- cf )
2006-03-15 18:24:59 -05:00
t <CFFileSystemURL> [
f swap CFBundleCreate
] keep CFRelease ;
2006-02-09 20:36:11 -05:00
: load-framework ( name -- )
dup <CFBundle> [
CFBundleLoadExecutable drop
] [
"Cannot load bundled named " swap append throw
] ?if ;
2006-03-14 21:09:25 -05:00
: running.app? ( -- ? )
#! Test if we're running Factor.app.
2006-03-19 15:43:40 -05:00
"Contents/Resources" image subseq? ;