]> gitweb.factorcode.org Git - factor.git/blobdiff - basis/cocoa/plists/plists.factor
Updating code to use with-out-parameters
[factor.git] / basis / cocoa / plists / plists.factor
index 845061e6101855a6d91a7a753d9af6642ffa780d..80d58e634061525383bd2db22899468c62a8e913 100644 (file)
@@ -4,8 +4,8 @@
 USING: strings arrays hashtables assocs sequences fry macros
 cocoa.messages cocoa.classes cocoa.application cocoa kernel
 namespaces io.backend math cocoa.enumeration byte-arrays
-combinators alien.c-types words core-foundation
-core-foundation.data core-foundation.utilities ;
+combinators alien.c-types alien.data words core-foundation
+quotations core-foundation.data core-foundation.utilities ;
 IN: cocoa.plists
 
 : >plist ( value -- plist ) >cf -> autorelease ;
@@ -32,19 +32,27 @@ DEFER: plist>
     [ plist> ] NSFastEnumeration-map ;
 
 : (plist-NSDictionary>) ( NSDictionary -- hashtable )
-    dup [ tuck -> valueForKey: [ plist> ] bi@ 2array ] with
+    dup [ [ nip ] [ -> valueForKey: ] 2bi [ plist> ] bi@ 2array ] with
     NSFastEnumeration-map >hashtable ;
 
 : (read-plist) ( NSData -- id )
-    NSPropertyListSerialization swap kCFPropertyListImmutable f f <void*>
-    [ -> propertyListFromData:mutabilityOption:format:errorDescription: ] keep
-    *void* [ -> release "read-plist failed" throw ] when* ;
+    NSPropertyListSerialization swap kCFPropertyListImmutable f
+    { void* }
+    [ -> propertyListFromData:mutabilityOption:format:errorDescription: ] [ ]
+    with-out-parameters
+    [ -> release "read-plist failed" throw ] when* ;
 
 MACRO: objc-class-case ( alist -- quot )
-    [ [ '[ dup _ execute -> isKindOfClass: c-bool> ] ] dip ] assoc-map '[ _ cond ] ;
+    [
+        dup callable?
+        [ first2 [ '[ dup _ execute -> isKindOfClass: c-bool> ] ] dip 2array ]
+        unless
+    ] map '[ _ cond ] ;
 
 PRIVATE>
 
+ERROR: invalid-plist-object object ;
+
 : plist> ( plist -- value )
     {
         { NSString [ (plist-NSString>) ] }
@@ -53,6 +61,7 @@ PRIVATE>
         { NSArray [ (plist-NSArray>) ] }
         { NSDictionary [ (plist-NSDictionary>) ] }
         { NSObject [ ] }
+        [ invalid-plist-object ]
     } objc-class-case ;
 
 : read-plist ( path -- assoc )