factor/library/cocoa/core-foundation.factor

76 lines
2.2 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
USING: alien arrays errors hashtables kernel 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-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 ) ;
FUNCTION: void* CFStringCreateWithCString ( void* allocator, ushort* 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-14 21:09:25 -05:00
FUNCTION: ushort* CFStringGetCStringPtr ( void* theString, int encoding ) ;
2006-02-09 22:11:22 -05:00
2006-02-09 20:36:11 -05:00
FUNCTION: void* CFBundleCreate ( void* allocator, void* bundleURL ) ;
2006-03-14 21:09:25 -05:00
FUNCTION: void* CFBundleGetMainBundle ( ) ;
FUNCTION: void* CFBundleCopyExecutableURL ( void* bundle ) ;
2006-02-09 20:36:11 -05:00
FUNCTION: void* CFBundleGetFunctionPointerForName ( void* bundle, void* functionName ) ;
FUNCTION: bool CFBundleLoadExecutable ( void* bundle ) ;
FUNCTION: void CFRelease ( void* cf ) ;
: <CFString> ( string -- cf )
2006-03-14 21:09:25 -05:00
f swap kCFStringEncodingUnicode CFStringCreateWithCString ;
2006-02-09 20:36:11 -05:00
2006-02-09 22:11:22 -05:00
: CF>string ( string -- string )
2006-03-14 21:09:25 -05:00
kCFStringEncodingUnicode CFStringGetCStringPtr ;
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 )
t <CFFileSystemURL> f over CFBundleCreate swap CFRelease ;
: load-framework ( name -- )
dup <CFBundle> [
CFBundleLoadExecutable drop
] [
"Cannot load bundled named " swap append throw
] ?if ;
2006-03-14 21:09:25 -05:00
: executable ( -- path )
CFBundleGetMainBundle CFBundleCopyExecutableURL [
kCFURLPOSIXPathStyle CFURLCopyFileSystemPath
[ CF>string ] keep CFRelease
] keep CFRelease ;
: running.app? ( -- ? )
#! Test if we're running Factor.app.
executable "Contents/MacOS/Factor" tail? ;
IN: kernel
: default-shell running.app? "ui" "tty" ? ;