handle NSFastEnumeration case when the item pointer is returned in the NSFastEnumerationState struct. add words for converting plist objects to Factor structures
parent
6d7a41a1b5
commit
8174a0967c
|
@ -43,6 +43,7 @@ SYMBOL: super-sent-messages
|
||||||
"NSArray"
|
"NSArray"
|
||||||
"NSAutoreleasePool"
|
"NSAutoreleasePool"
|
||||||
"NSBundle"
|
"NSBundle"
|
||||||
|
"NSData"
|
||||||
"NSDictionary"
|
"NSDictionary"
|
||||||
"NSError"
|
"NSError"
|
||||||
"NSEvent"
|
"NSEvent"
|
||||||
|
@ -53,6 +54,7 @@ SYMBOL: super-sent-messages
|
||||||
"NSNib"
|
"NSNib"
|
||||||
"NSNotification"
|
"NSNotification"
|
||||||
"NSNotificationCenter"
|
"NSNotificationCenter"
|
||||||
|
"NSNumber"
|
||||||
"NSObject"
|
"NSObject"
|
||||||
"NSOpenGLContext"
|
"NSOpenGLContext"
|
||||||
"NSOpenGLPixelFormat"
|
"NSOpenGLPixelFormat"
|
||||||
|
|
|
@ -12,8 +12,10 @@ IN: cocoa.enumeration
|
||||||
:: (NSFastEnumeration-each) ( object quot state stackbuf count -- )
|
:: (NSFastEnumeration-each) ( object quot state stackbuf count -- )
|
||||||
object state stackbuf count -> countByEnumeratingWithState:objects:count:
|
object state stackbuf count -> countByEnumeratingWithState:objects:count:
|
||||||
dup zero? [ drop ] [
|
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
|
] if ; inline
|
||||||
|
|
||||||
: NSFastEnumeration-each ( object quot -- )
|
: NSFastEnumeration-each ( object quot -- )
|
||||||
|
|
|
@ -2,7 +2,8 @@
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: strings arrays hashtables assocs sequences
|
USING: strings arrays hashtables assocs sequences
|
||||||
cocoa.messages cocoa.classes cocoa.application cocoa kernel
|
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
|
IN: cocoa.plists
|
||||||
|
|
||||||
: assoc>NSDictionary ( assoc -- alien )
|
: assoc>NSDictionary ( assoc -- alien )
|
||||||
|
@ -17,3 +18,33 @@ IN: cocoa.plists
|
||||||
>r assoc>NSDictionary
|
>r assoc>NSDictionary
|
||||||
r> normalize-path <NSString> 0 -> writeToFile:atomically:
|
r> normalize-path <NSString> 0 -> writeToFile:atomically:
|
||||||
[ "write-plist failed" throw ] unless ;
|
[ "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 <byte-array> [ -> 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 ;
|
||||||
|
|
Loading…
Reference in New Issue