Better error checking for Cocoa bridge, update for NSRect -> CGRect renaming

db4
Slava Pestov 2009-01-21 19:47:17 -06:00
parent a5737a51b5
commit b856cc5491
3 changed files with 13 additions and 6 deletions

View File

@ -52,7 +52,7 @@ CLASS: {
{ +name+ "Bar" }
} {
"bar"
"CGRect"
"NSRect"
{ "id" "SEL" }
[ 2drop test-foo "x" get ]
} {

View File

@ -1,4 +1,4 @@
! Copyright (C) 2006, 2008 Slava Pestov.
! Copyright (C) 2006, 2009 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
USING: accessors alien alien.c-types alien.strings arrays assocs
continuations combinators compiler compiler.alien kernel math
@ -167,13 +167,19 @@ assoc-union alien>objc-types set-global
drop "void*"
] unless ;
ERROR: no-objc-type name ;
: decode-type ( ch -- ctype )
1string dup objc>alien-types get at
[ ] [ no-objc-type ] ?if ;
: (parse-objc-type) ( i string -- ctype )
[ [ 1+ ] dip ] [ nth ] 2bi {
{ [ dup "rnNoORV" member? ] [ drop (parse-objc-type) ] }
{ [ dup CHAR: ^ = ] [ 3drop "void*" ] }
{ [ dup CHAR: { = ] [ drop objc-struct-type ] }
{ [ dup CHAR: [ = ] [ 3drop "void*" ] }
[ 2nip 1string objc>alien-types get at ]
[ 2nip decode-type ]
} cond ;
: parse-objc-type ( string -- ctype ) 0 swap (parse-objc-type) ;

View File

@ -32,10 +32,11 @@ IN: cocoa.subclassing
[ add-protocols ] [ add-methods ] [ objc_registerClassPair ]
tri ;
: encode-type ( type -- encoded )
dup alien>objc-types get at [ ] [ no-objc-type ] ?if ;
: encode-types ( return types -- encoding )
swap prefix [
alien>objc-types get at "0" append
] map concat ;
swap prefix [ encode-type "0" append ] map concat ;
: prepare-method ( ret types quot -- type imp )
[ [ encode-types ] 2keep ] dip [