#FEATURE by cg
authorClaus Gittinger <cg@exept.de>
Mon, 04 Mar 2019 09:41:45 +0100
changeset 23828 cbcc99660889
parent 23827 d9f5a3454db2
child 23829 209adc65cf44
#FEATURE by cg class: ExternalLibraryFunction added: #invokeObjCOn: #invokeObjCOn:withArguments: #prepareObjCInvoke comment/format in: #invoke #invokeCPPVirtualOn: #invokeCPPVirtualOn:with: #invokeCPPVirtualOn:with:with: #invokeCPPVirtualOn:with:with:with: #invokeCPPVirtualOn:with:with:with:with: #invokeCPPVirtualOn:withArguments: #invokeObjCFFIOn:withArguments: #invokeWith: #invokeWith:with: #invokeWith:with:with: #invokeWith:with:with:with: #invokeWithArguments: class: ExternalLibraryFunction class added: #invokeSelectors
ExternalLibraryFunction.st
--- a/ExternalLibraryFunction.st	Mon Mar 04 09:35:04 2019 +0100
+++ b/ExternalLibraryFunction.st	Mon Mar 04 09:41:45 2019 +0100
@@ -1,3 +1,5 @@
+"{ Encoding: utf8 }"
+
 "
  COPYRIGHT (c) 2004 by eXept Software AG
 	      All Rights Reserved
@@ -202,7 +204,7 @@
   Synchronous vs. Asynchronous calls:
 
     by default, foreign function calls are synchronous, effectively blocking the whole ST/X system
-    (that is by purpose,´because most C-code is not prepared for being interrupted, and also, normal
+    (that is by purpose,´because most C-code is not prepared for being interrupted, and also, normal
      code is not prepared for a garbage collector to move objects around, while another C thread might
      access the data...).
     Therefore, the following will block all ST/X activity for 10 seconds
@@ -491,6 +493,31 @@
     ^ CALLTYPE_UNIX64
 
     "Modified: / 01-08-2006 / 13:44:57 / cg"
+!
+
+invokeSelectors
+    ^ #(
+        #'invoke'
+        #'invokeWith:'
+        #'invokeWith:with:'
+        #'invokeWith:with:with:'
+        #'invokeWith:with:with:with:'
+        #'invokeWithArguments:'
+        #'invokeCPPVirtualOn:'
+        #'invokeCPPVirtualOn:with:'
+        #'invokeCPPVirtualOn:with:with:'
+        #'invokeCPPVirtualOn:with:with:with:'
+        #'invokeCPPVirtualOn:with:with:with:with:'
+        #'invokeCPPVirtualOn:withArguments:'
+        #'invokeObjCOn:'
+        #'invokeObjCOn:with:'
+        #'invokeObjCOn:with:with:'
+        #'invokeObjCOn:with:with:with:'
+        #'invokeObjCOn:with:with:with:with:'
+        #'invokeObjCOn:withArguments:'
+    )
+
+    "Created: / 04-03-2019 / 09:35:51 / Claus Gittinger"
 ! !
 
 !ExternalLibraryFunction class methodsFor:'debugging'!
@@ -848,89 +875,168 @@
 !ExternalLibraryFunction methodsFor:'invoking'!
 
 invoke
+    "call the function with no arguments"
+
     self hasCode ifFalse:[
-	self prepareInvoke.
+        self prepareInvoke.
     ].
     ^ self invokeFFIwithArguments:nil forCPPInstance:nil
+
+    "Modified (comment): / 04-03-2019 / 09:41:20 / Claus Gittinger"
 !
 
 invokeCPPVirtualOn:anInstance
+    "call a CPP virtual function with no arguments"
+    
     self hasCode ifFalse:[
-	self prepareInvoke.
+        self prepareInvoke.
     ].
-    ^ self invokeCPPVirtualFFIOn:anInstance withArguments:nil
+    ^ self invokeFFIwithArguments:nil forCPPInstance:anInstance
+
+    "Modified (comment): / 04-03-2019 / 09:39:27 / Claus Gittinger"
 !
 
-invokeCPPVirtualOn:instance with:arg
+invokeCPPVirtualOn:anInstance with:arg
+    "call a CPP virtual function with 1 argument"
+
     self hasCode ifFalse:[
-	self prepareInvoke.
+        self prepareInvoke.
     ].
-    ^ self invokeCPPVirtualFFIOn:instance withArguments:(Array with:arg)
+    ^ self 
+        invokeFFIwithArguments:(Array with:arg) 
+        forCPPInstance:anInstance
+
+    "Modified (comment): / 04-03-2019 / 09:39:34 / Claus Gittinger"
 !
 
-invokeCPPVirtualOn:instance with:arg1 with:arg2
+invokeCPPVirtualOn:anInstance with:arg1 with:arg2
+    "call a CPP virtual function with 2 arguments"
+
     self hasCode ifFalse:[
-	self prepareInvoke.
+        self prepareInvoke.
     ].
-    ^ self invokeCPPVirtualFFIOn:instance withArguments:(Array with:arg1 with:arg2)
+    ^ self 
+        invokeFFIwithArguments:(Array with:arg1 with:arg2) 
+        forCPPInstance:anInstance
+
+    "Modified (comment): / 04-03-2019 / 09:39:38 / Claus Gittinger"
+!
+
+invokeCPPVirtualOn:anInstance with:arg1 with:arg2 with:arg3
+    "call a CPP virtual function with 3 arguments"
+
+    self hasCode ifFalse:[
+        self prepareInvoke.
+    ].
+    ^ self 
+        invokeFFIwithArguments:(Array with:arg1 with:arg2 with:arg3) 
+        forCPPInstance:anInstance
+
+    "Modified (comment): / 04-03-2019 / 09:39:43 / Claus Gittinger"
 !
 
-invokeCPPVirtualOn:instance with:arg1 with:arg2 with:arg3
+invokeCPPVirtualOn:anInstance with:arg1 with:arg2 with:arg3 with:arg4
+    "call a CPP virtual function with 4 arguments"
+
     self hasCode ifFalse:[
-	self prepareInvoke.
+        self prepareInvoke.
     ].
-    ^ self invokeCPPVirtualFFIOn:instance withArguments:(Array with:arg1 with:arg2 with:arg3)
+    ^ self 
+        invokeFFIwithArguments:(Array with:arg1 with:arg2 with:arg3 with:arg4) 
+        forCPPInstance:anInstance
+
+    "Modified (comment): / 04-03-2019 / 09:39:48 / Claus Gittinger"
 !
 
-invokeCPPVirtualOn:instance with:arg1 with:arg2 with:arg3 with:arg4
+invokeCPPVirtualOn:anInstance withArguments:args
+    "call a CPP virtual function with up to maxArgs (15) arguments"
+
     self hasCode ifFalse:[
-	self prepareInvoke.
+        self prepareInvoke.
     ].
-    ^ self invokeCPPVirtualFFIOn:instance withArguments:(Array with:arg1 with:arg2 with:arg3 with:arg4)
+    ^ self 
+        invokeFFIwithArguments:args 
+        forCPPInstance:anInstance
+
+    "Modified (comment): / 04-03-2019 / 09:39:57 / Claus Gittinger"
 !
 
-invokeCPPVirtualOn:instance withArguments:args
+invokeObjCOn:anInstance
+    "call an ObjC method with no arguments"
+
     self hasCode ifFalse:[
-	self prepareInvoke.
+        self prepareObjCInvoke.
     ].
-    ^ self invokeCPPVirtualFFIOn:instance withArguments:args
+    ^ self invokeFFIwithArguments:nil forCPPInstance:anInstance
+
+    "Created: / 04-03-2019 / 09:12:12 / Claus Gittinger"
+!
+
+invokeObjCOn:anInstance withArguments:args
+    "call an ObjC method with up to maxArgs (15) arguments"
+
+    self hasCode ifFalse:[
+        self prepareObjCInvoke.
+    ].
+    ^ self invokeFFIwithArguments:args forCPPInstance:anInstance
+
+    "Created: / 04-03-2019 / 09:39:03 / Claus Gittinger"
 !
 
 invokeWith:arg
+    "call the function with 1 argument"
+
     self hasCode ifFalse:[
-	self prepareInvoke.
+        self prepareInvoke.
     ].
     ^ self invokeFFIwithArguments:(Array with:arg) forCPPInstance:nil
+
+    "Modified (comment): / 04-03-2019 / 09:41:14 / Claus Gittinger"
 !
 
 invokeWith:arg1 with:arg2
+    "call the function with 2 arguments"
+
     self hasCode ifFalse:[
-	self prepareInvoke.
+        self prepareInvoke.
     ].
     ^ self invokeFFIwithArguments:(Array with:arg1 with:arg2) forCPPInstance:nil
+
+    "Modified (comment): / 04-03-2019 / 09:41:07 / Claus Gittinger"
 !
 
 invokeWith:arg1 with:arg2 with:arg3
+    "call the function with 3 arguments"
+
     self hasCode ifFalse:[
-	self prepareInvoke.
+        self prepareInvoke.
     ].
     ^ self invokeFFIwithArguments:(Array with:arg1 with:arg2 with:arg3) forCPPInstance:nil
+
+    "Modified (comment): / 04-03-2019 / 09:41:01 / Claus Gittinger"
 !
 
 invokeWith:arg1 with:arg2 with:arg3 with:arg4
+    "call the function with 4 arguments"
+
     self hasCode ifFalse:[
-	self prepareInvoke.
+        self prepareInvoke.
     ].
     ^ self invokeFFIwithArguments:(Array with:arg1 with:arg2 with:arg3 with:arg4) forCPPInstance:nil
+
+    "Modified (comment): / 04-03-2019 / 09:40:56 / Claus Gittinger"
 !
 
 invokeWithArguments:argArray
+    "call the function with up to maxArgs (15) arguments"
+
     self hasCode ifFalse:[
-	self prepareInvoke.
+        self prepareInvoke.
     ].
     ^ self invokeFFIwithArguments:argArray forCPPInstance:nil
 
     "Modified: / 01-08-2006 / 16:04:08 / cg"
+    "Modified (comment): / 04-03-2019 / 09:40:48 / Claus Gittinger"
 ! !
 
 !ExternalLibraryFunction methodsFor:'printing'!
@@ -1149,6 +1255,12 @@
 	self linkToModule.
 	self adjustTypes.
     ].
+!
+
+prepareObjCInvoke
+    "called before invoked"
+
+    "Created: / 04-03-2019 / 09:20:39 / Claus Gittinger"
 ! !
 
 !ExternalLibraryFunction methodsFor:'private-accessing'!