diff --git a/extra/cocoa/application/application.factor b/extra/cocoa/application/application.factor index 3e6f8c5be7..a28952ea33 100755 --- a/extra/cocoa/application/application.factor +++ b/extra/cocoa/application/application.factor @@ -3,12 +3,20 @@ USING: alien alien.syntax io kernel namespaces core-foundation core-foundation.run-loop cocoa.messages cocoa cocoa.classes cocoa.runtime sequences threads debugger init summary -kernel.private ; +kernel.private assocs ; IN: cocoa.application : ( str -- alien ) -> autorelease ; - : ( seq -- alien ) -> autorelease ; +: ( number -- alien ) -> autorelease ; +: ( byte-array -- alien ) -> autorelease ; +: ( assoc -- alien ) + NSMutableDictionary over assoc-size -> dictionaryWithCapacity: + [ + [ + spin -> setObject:forKey: + ] curry assoc-each + ] keep ; : NSApplicationDelegateReplySuccess 0 ; : NSApplicationDelegateReplyCancel 1 ; diff --git a/extra/cocoa/plists/plists.factor b/extra/cocoa/plists/plists.factor index 4ffc1db139..139e0840e1 100644 --- a/extra/cocoa/plists/plists.factor +++ b/extra/cocoa/plists/plists.factor @@ -6,16 +6,25 @@ namespaces io.backend math cocoa.enumeration byte-arrays combinators alien.c-types ; IN: cocoa.plists -: assoc>NSDictionary ( assoc -- alien ) - NSMutableDictionary over assoc-size -> dictionaryWithCapacity: - [ - [ - spin [ ] bi@ -> setObject:forKey: - ] curry assoc-each - ] keep ; +GENERIC: >plist ( value -- plist ) + +M: number >plist + ; +M: t >plist + ; +M: f >plist + ; +M: string >plist + ; +M: byte-array >plist + ; +M: hashtable >plist + [ [ >plist ] bi@ ] assoc-map ; +M: sequence >plist + [ >plist ] map ; : write-plist ( assoc path -- ) - >r assoc>NSDictionary + >r >plist r> normalize-path 0 -> writeToFile:atomically: [ "write-plist failed" throw ] unless ; diff --git a/extra/core-foundation/core-foundation.factor b/extra/core-foundation/core-foundation.factor index b91493d2be..e1c2c4c517 100644 --- a/extra/core-foundation/core-foundation.factor +++ b/extra/core-foundation/core-foundation.factor @@ -6,16 +6,44 @@ IN: core-foundation TYPEDEF: void* CFAllocatorRef TYPEDEF: void* CFArrayRef +TYPEDEF: void* CFDataRef +TYPEDEF: void* CFDictionaryRef +TYPEDEF: void* CFMutableDictionaryRef +TYPEDEF: void* CFNumberRef TYPEDEF: void* CFBundleRef +TYPEDEF: void* CFRunLoopRef +TYPEDEF: void* CFSetRef TYPEDEF: void* CFStringRef TYPEDEF: void* CFURLRef TYPEDEF: void* CFUUIDRef +TYPEDEF: void* CFTypeRef TYPEDEF: bool Boolean TYPEDEF: int CFIndex TYPEDEF: int SInt32 +TYPEDEF: uint UInt32 +TYPEDEF: uint CFTypeID TYPEDEF: double CFTimeInterval TYPEDEF: double CFAbsoluteTime +TYPEDEF: int CFNumberType +: kCFNumberSInt8Type 1 ; inline +: kCFNumberSInt16Type 2 ; inline +: kCFNumberSInt32Type 3 ; inline +: kCFNumberSInt64Type 4 ; inline +: kCFNumberFloat32Type 5 ; inline +: kCFNumberFloat64Type 6 ; inline +: kCFNumberCharType 7 ; inline +: kCFNumberShortType 8 ; inline +: kCFNumberIntType 9 ; inline +: kCFNumberLongType 10 ; inline +: kCFNumberLongLongType 11 ; inline +: kCFNumberFloatType 12 ; inline +: kCFNumberDoubleType 13 ; inline +: kCFNumberCFIndexType 14 ; inline +: kCFNumberNSIntegerType 15 ; inline +: kCFNumberCGFloatType 16 ; inline +: kCFNumberMaxType 16 ; inline + FUNCTION: CFArrayRef CFArrayCreateMutable ( CFAllocatorRef allocator, CFIndex capacity, void* callbacks ) ; FUNCTION: void* CFArrayGetValueAtIndex ( CFArrayRef array, CFIndex idx ) ; @@ -39,11 +67,18 @@ FUNCTION: CFIndex CFStringGetLength ( CFStringRef theString ) ; FUNCTION: void CFStringGetCharacters ( void* theString, CFIndex start, CFIndex length, void* buffer ) ; +FUNCTION: CFNumberRef CFNumberCreate ( CFAllocatorRef allocator, CFNumberType theType, void* valuePtr ) ; + +FUNCTION: CFDataRef CFDataCreate ( CFAllocatorRef allocator, uchar* bytes, CFIndex length ) ; + FUNCTION: CFBundleRef CFBundleCreate ( CFAllocatorRef allocator, CFURLRef bundleURL ) ; FUNCTION: Boolean CFBundleLoadExecutable ( CFBundleRef bundle ) ; -FUNCTION: void CFRelease ( void* cf ) ; +FUNCTION: CFTypeRef CFRetain ( CFTypeRef cf ) ; +FUNCTION: void CFRelease ( CFTypeRef cf ) ; + +FUNCTION: CFTypeID CFGetTypeID ( CFTypeRef cf ) ; : CF>array ( alien -- array ) dup CFArrayGetCount [ CFArrayGetValueAtIndex ] with map ; @@ -81,6 +116,19 @@ FUNCTION: void CFRelease ( void* cf ) ; f swap CFBundleCreate ] keep CFRelease ; +GENERIC: ( number -- alien ) +M: integer + [ f kCFNumberLongLongType ] dip CFNumberCreate ; +M: float + [ f kCFNumberDoubleType ] dip CFNumberCreate ; +M: t + drop f kCFNumberIntType 1 CFNumberCreate ; +M: f + drop f kCFNumberIntType 0 CFNumberCreate ; + +: ( byte-array -- alien ) + [ f ] dip dup length CFDataCreate ; + : load-framework ( name -- ) dup [ CFBundleLoadExecutable drop