! See https://factorcode.org/license.txt for BSD license.
USING: accessors alien alien.c-types alien.data alien.strings
arrays assocs classes.struct cocoa.runtime cocoa.types
-combinators core-graphics.types generalizations io
+combinators continuations core-graphics.types generalizations io
io.encodings.utf8 kernel layouts libc make math math.parser
namespaces sequences sets specialized-arrays
splitting stack-checker strings words ;
[ method-arg-type ] with map ;
: method-return-type ( method -- ctype )
- method_copyReturnType
- [
- utf8 alien>string dup string>number [
- "unknown objc return type: " prepend
- [ print ] with-output>error
- f
- ] [ parse-objc-type ] if
- ] keep (free) ;
+ method_copyReturnType [ utf8 alien>string ] [ (free) ] bi ;
+
+: method-return-type-parsed ( method -- ctype/f )
+ method-return-type
+ [ parse-objc-type ] [ 2drop f ] recover ;
: method-signature ( method -- signature )
- [ method-return-type ] [ method-arg-types ] bi 2array ;
+ [ method-return-type-parsed ] [ method-arg-types ] bi 2array ;
: method-name ( method -- name )
method_getName sel_getName ;
+: warn-unknown-objc-method ( classname method-name method -- )
+ '[
+ _ write bl
+ _ "`" dup surround write bl
+ "has unknown method-return-type:" write bl
+ _ method-return-type print
+ ] with-output>error ;
+
:: register-objc-method ( classname method -- )
method method-signature :> signature
method method-name :> name
signature cache-stubs
signature name objc-methods get set-at
signature fullname objc-methods get set-at
- ] when ;
+ ] [
+ classname name method warn-unknown-objc-method
+ ] if ;
: method-collisions ( -- collisions )
objc-methods get >alist
[ first "." split1 nip ] collect-by
[ nip values members length 1 > ] assoc-filter ;
+: method-count ( class -- c-direct-array )
+ 0 uint <ref> [ class_copyMethodList (free) ] keep uint deref ;
+
: each-method-in-class ( class quot: ( classname method -- ) -- )
[
[ class_getName ] keep