]> gitweb.factorcode.org Git - factor.git/commitdiff
cocoa: Allow ?-> syntax for methods that might not exist.
authorDoug Coleman <doug.coleman@gmail.com>
Thu, 1 Jun 2017 16:55:08 +0000 (11:55 -0500)
committerDoug Coleman <doug.coleman@gmail.com>
Thu, 1 Jun 2017 21:53:05 +0000 (16:53 -0500)
If a method doesn't exist we need to provide a signature so the stack is balanced. This should also allow deploying from macOS versions that do not contain methods to ones that do. This is an alternative to asking a class if it provides a selector.

basis/cocoa/cocoa.factor
basis/cocoa/messages/messages.factor
basis/cocoa/touchbar/touchbar.factor

index 9fa68ff900c4dfc713e1d2c19bae8db24622f084..e92f0f9068aa621aec6433c4746276756cd85ef4 100644 (file)
@@ -14,6 +14,8 @@ SYMBOL: sent-messages
 
 SYNTAX: -> scan-token dup remember-send suffix! \ send suffix! ;
 
+SYNTAX: ?-> scan-token dup remember-send suffix! \ ?send suffix! ;
+
 SYNTAX: SEL:
     scan-token
     [ remember-send ]
index cd0e932f2a1087868776b364748066ff32151254..4814a36e48beeba763efba1f82e183160529d472 100644 (file)
@@ -86,6 +86,14 @@ MACRO: (send) ( selector super? -- quot )
 
 : send ( receiver args... selector -- return... ) f (send) ; inline
 
+MACRO:: (?send) ( effect selector super? -- quot )
+    selector dup ?lookup-method effect or super?
+    [ make-prepare-send ] 2keep
+    super-message-senders message-senders ? get at
+    [ 1quotation append ] [ effect selector sender-stub 1quotation append ] if* ;
+
+: ?send ( receiver args... selector effect -- return... ) f (?send) ; inline
+
 : super-send ( receiver args... selector -- return... ) t (send) ; inline
 
 ! Runtime introspection
index b098770c6ccd654ed3727afa5052c463ca7a560e..8b9bfd42849c64e591515985d4b0b1c5bb328e2b 100644 (file)
@@ -1,8 +1,8 @@
 ! Copyright (C) 2017 Doug Coleman.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: accessors alien.enums alien.syntax cocoa cocoa.classes
-cocoa.messages combinators core-foundation.strings kernel locals
-namespaces sequences words ;
+USING: accessors alien.c-types alien.enums alien.syntax cocoa
+cocoa.classes cocoa.messages cocoa.runtime combinators
+core-foundation.strings kernel locals namespaces sequences words ;
 IN: cocoa.touchbar
 
 ! ui.backend.cocoa.views creates buttons for each of these actions
@@ -15,17 +15,17 @@ ENUM: default-touchbar refresh-all-action auto-use-action ;
 
 : make-touchbar ( enum self -- touchbar )
     [ NSTouchBar -> alloc -> init dup ] dip -> setDelegate: {
-        [ swap enum>CFStringArray -> setDefaultItemIdentifiers: ]
-        [ swap enum>CFStringArray -> setCustomizationAllowedItemIdentifiers: ]
+        [ swap enum>CFStringArray { void { id SEL id } } ?-> setDefaultItemIdentifiers: ]
+        [ swap enum>CFStringArray { void { id SEL id } } ?-> setCustomizationAllowedItemIdentifiers: ]
         [ nip ]
     } 2cleave ;
 
 :: make-NSTouchBar-button ( self identifier label-string action-string -- button )
     NSCustomTouchBarItem -> alloc
-        identifier <CFString> -> initWithIdentifier: :> item
+        identifier <CFString> { id { id SEL id } } ?-> initWithIdentifier: :> item
         NSButton
             label-string <CFString>
             self
-            action-string lookup-selector -> buttonWithTitle:target:action: :> button
+            action-string lookup-selector { id { id SEL id id SEL } } ?-> buttonWithTitle:target:action: :> button
         item button -> setView:
         item ;