more documentation; removed leftover halt.
authorClaus Gittinger <cg@exept.de>
Thu, 14 Jun 2007 11:28:16 +0200
changeset 10611 0ca921c0a7a1
parent 10610 44dcb48a04c7
child 10612 53e2ead58227
more documentation; removed leftover halt.
ExternalFunctionCallback.st
--- a/ExternalFunctionCallback.st	Wed Jun 13 23:15:15 2007 +0200
+++ b/ExternalFunctionCallback.st	Thu Jun 14 11:28:16 2007 +0200
@@ -243,8 +243,26 @@
     i.e. it creates a closure, which as seen from C-code looks like an ordinary
     function pointer, but when invoked evaluates a smalltalk block.
 
+    A callback is created with:
+       cb := ExternalFunctionCallback new.
+    the arguments (as passed from the C-caller into ST) 
+    and the returnValue (from ST to the C-caller) are specified with:
+       cb returnType:#bool argumentTypes:#(uint).
+    Then, the code is generated with:
+       cb generateClosure.
+
+    After that, the callBack-functions address can be aquired with:
+       cb address.  'can be passed to C'.
+    and handed out to C. (you can also hand out the callBack directly - as it is a subclass of
+    ExternalBytes.
+    The actual action of the callback can be changed (at any time later) with:
+        cb action:[:args | Transcript showCR:args. true].
+
+    Eventually, the callback should be released:
+        cb release.
+
     [author:]
-	Claus Gittinger
+        Claus Gittinger
 "
 !
 
@@ -254,12 +272,16 @@
 
     cb := ExternalFunctionCallback new.
     cb returnType:#bool argumentTypes:#(uint).
+    cb generateClosure.
     cb action:[:args | Transcript showCR:args. true].
-    cb generateClosure.
-
     cb address.  'can be passed to C'.
 
     ExternalFunctionCallback testCall:cb withArgument:123.
+
+    cb action:[:args | Transcript show:'hello '; showCR:args. true].
+
+    ExternalFunctionCallback testCall:cb withArgument:123.
+
     cb release
 "
 ! !
@@ -299,9 +321,8 @@
      any other things which confuse C
      (its probably a good idea to write something into a queue here)"
 
-self halt.
     action notNil ifTrue:[
-	^ action valueWithArguments:argList
+        ^ action valueWithArguments:argList
     ].
     ^ nil
 ! !
@@ -678,5 +699,5 @@
 !ExternalFunctionCallback class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/ExternalFunctionCallback.st,v 1.3 2007-06-13 21:15:15 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/ExternalFunctionCallback.st,v 1.4 2007-06-14 09:28:16 cg Exp $'
 ! !