diff --git a/extra/cocoa/cocoa.factor b/extra/cocoa/cocoa.factor index a3ac3e89ce..907d75fd84 100755 --- a/extra/cocoa/cocoa.factor +++ b/extra/cocoa/cocoa.factor @@ -43,6 +43,7 @@ SYMBOL: super-sent-messages "NSArray" "NSAutoreleasePool" "NSBundle" + "NSData" "NSDictionary" "NSError" "NSEvent" @@ -53,6 +54,7 @@ SYMBOL: super-sent-messages "NSNib" "NSNotification" "NSNotificationCenter" + "NSNumber" "NSObject" "NSOpenGLContext" "NSOpenGLPixelFormat" diff --git a/extra/cocoa/enumeration/enumeration.factor b/extra/cocoa/enumeration/enumeration.factor index 5e3e9c5e44..ae1766b1a9 100644 --- a/extra/cocoa/enumeration/enumeration.factor +++ b/extra/cocoa/enumeration/enumeration.factor @@ -12,8 +12,10 @@ IN: cocoa.enumeration :: (NSFastEnumeration-each) ( object quot state stackbuf count -- ) object state stackbuf count -> countByEnumeratingWithState:objects:count: dup zero? [ drop ] [ - [ stackbuf void*-nth quot call ] each - object quot state stackbuf count (NSFastEnumeration-each) + [ + state NSFastEnumerationState-itemsPtr dup stackbuf ? + void*-nth quot call + ] each object quot state stackbuf count (NSFastEnumeration-each) ] if ; inline : NSFastEnumeration-each ( object quot -- ) diff --git a/extra/cocoa/plists/plists.factor b/extra/cocoa/plists/plists.factor index 9e05773f53..4ffc1db139 100644 --- a/extra/cocoa/plists/plists.factor +++ b/extra/cocoa/plists/plists.factor @@ -2,7 +2,8 @@ ! See http://factorcode.org/license.txt for BSD license. USING: strings arrays hashtables assocs sequences cocoa.messages cocoa.classes cocoa.application cocoa kernel -namespaces io.backend ; +namespaces io.backend math cocoa.enumeration byte-arrays +combinators alien.c-types ; IN: cocoa.plists : assoc>NSDictionary ( assoc -- alien ) @@ -17,3 +18,33 @@ IN: cocoa.plists >r assoc>NSDictionary r> normalize-path 0 -> writeToFile:atomically: [ "write-plist failed" throw ] unless ; + +DEFER: plist> + +: (plist-NSString>) ( NSString -- string ) + -> UTF8String ; + +: (plist-NSNumber>) ( NSNumber -- number ) + dup -> doubleValue dup >integer = + [ -> longLongValue ] + [ -> doubleValue ] if ; + +: (plist-NSData>) ( NSData -- byte-array ) + dup -> length [ -> getBytes: ] keep ; + +: (plist-NSArray>) ( NSArray -- vector ) + [ plist> ] NSFastEnumeration-map ; + +: (plist-NSDictionary>) ( NSDictionary -- hashtable ) + dup [ [ -> valueForKey: ] keep swap [ plist> ] bi@ 2array ] with + NSFastEnumeration-map >hashtable ; + +: plist> ( plist -- value ) + { + { [ dup NSString -> isKindOfClass: c-bool> ] [ (plist-NSString>) ] } + { [ dup NSNumber -> isKindOfClass: c-bool> ] [ (plist-NSNumber>) ] } + { [ dup NSData -> isKindOfClass: c-bool> ] [ (plist-NSData>) ] } + { [ dup NSArray -> isKindOfClass: c-bool> ] [ (plist-NSArray>) ] } + { [ dup NSDictionary -> isKindOfClass: c-bool> ] [ (plist-NSDictionary>) ] } + [ ] + } cond ;