commentary
authorClaus Gittinger <cg@exept.de>
Mon, 22 Apr 1996 18:14:01 +0200
changeset 1257 f98014b76dd1
parent 1256 249fd57abee5
child 1258 da1ef936ecdd
commentary
ExtFunc.st
ExternalFunction.st
--- a/ExtFunc.st	Mon Apr 22 17:41:09 1996 +0200
+++ b/ExtFunc.st	Mon Apr 22 18:14:01 1996 +0200
@@ -75,30 +75,40 @@
     Instances of this class represent external (non-Smalltalk) functions.
 
     Also, the class provides access to custom functions 
-    These custom functions enable you to call c functions even if no
-    stc is available (they are kind of what user-primitives are in ST-80).
-    You can register your own custom C-functions and relink ST/X from the
-    binaries.
+    These custom functions enable you to call c functions 
+    even if no stc compiler is available 
+    (they are kind of what user-primitives are in ST-80).
+    You can register your own custom C-functions in a private main.c
+    and relink ST/X from the binaries.
     (see the demo functions provided in main.c).
 
-    Non custom externalFunctions provide the basic low level mechanism
-    to call external C functions (as loaded dynamically by the ObjectLoader)
-    - however, this is still in construction and 
-      NOT yet published for general use.
+    If you have the stc compiler, we recommend using inline primitive
+    code: its much easier to enter, compile, debug and maintain.
+    (especially, to maintain, since the primitive code is contained
+     in the classes source/object file - while custom functions are 
+     external to the classLibraries).
 
-    For now, either use inline C-code, or use the customFunction call
-    mechanism.
+    In the furture, non custom externalFunctions will be created when
+    a non-ST shared library is loaded, and the contained C Functions will
+    be callable via those handles.
+    - however, this is still in construction and NOT yet published for 
+      general use. For now, either use inline C-code, or use the customFunction call
+      mechanism.
 "
 ! !
 
 !ExternalFunction class methodsFor:'initialization'!
 
 initialize
+    "create signals"
+
     InvalidCustomFunctionSignal isNil ifTrue:[
-	InvalidCustomFunctionSignal := ExecutionErrorSignal newSignalMayProceed:true.
-	InvalidCustomFunctionSignal nameClass:self message:#invalidCustomFunctionSignal.
-	InvalidCustomFunctionSignal notifierString:'attempt to execute unknown custom function'.
+        InvalidCustomFunctionSignal := ExecutionErrorSignal newSignalMayProceed:true.
+        InvalidCustomFunctionSignal nameClass:self message:#invalidCustomFunctionSignal.
+        InvalidCustomFunctionSignal notifierString:'attempt to execute unknown custom function'.
     ]
+
+    "Modified: 22.4.1996 / 18:08:55 / cg"
 ! !
 
 !ExternalFunction class methodsFor:'Signal constants'!
@@ -110,39 +120,57 @@
     ^ InvalidCustomFunctionSignal
 ! !
 
-!ExternalFunction class methodsFor:'custom functions'!
+!ExternalFunction class methodsFor:'calling custom functions'!
 
 callCustomFunction:nr
+    "call the custom function #nr without arguments"
+
     ^ self callCustomFunction:nr withArguments:#()
 
     "
      ExternalFunction callCustomFunction:0
      ExternalFunction callCustomFunction:999 
     "
+
+    "Modified: 22.4.1996 / 18:06:52 / cg"
 !
 
 callCustomFunction:nr with:arg
+    "call the custom function #nr with a single argument"
+
     ^ self callCustomFunction:nr withArguments:(Array with:arg)
 
     "
      ExternalFunction callCustomFunction:1 with:'hello world'
     "
+
+    "Modified: 22.4.1996 / 18:07:03 / cg"
 !
 
 callCustomFunction:nr with:arg1 with:arg2
+    "call the custom function #nr with two arguments"
+
     ^ self callCustomFunction:nr withArguments:(Array with:arg1 with:arg2)
 
     "
      ExternalFunction callCustomFunction:2 with:(Float pi) with:1.0
     "
+
+    "Modified: 22.4.1996 / 18:07:11 / cg"
 !
 
 callCustomFunction:nr with:arg1 with:arg2 with:arg3
+    "call the custom function #nr with three arguments"
+
     ^ self callCustomFunction:nr 
-		withArguments:(Array with:arg1 with:arg2 with:arg3)
+                withArguments:(Array with:arg1 with:arg2 with:arg3)
+
+    "Modified: 22.4.1996 / 18:07:18 / cg"
 !
 
 callCustomFunction:nr withArguments:argArray
+    "call the custom function #nr with arguments from argArray"
+
     |retVal called|
 
 %{
@@ -154,33 +182,33 @@
 
     called = false;
     if (__isSmallInteger(nr) && __isArray(argArray)) {
-	int nargs = __arraySize(argArray);
-	int functionNr;
+        int nargs = __arraySize(argArray);
+        int functionNr;
 
-	functionNr = __intVal(nr);
-	if ((functionNr >= 0) && (functionNr < __stxNCustomFunctions__)) {
-	    /*
-	     * now, call the function; passing nargs and arg-vector
-	     */
-	    func = __stxCustomFunctions__[functionNr].func;
-	    if (func) {
-		int ok;
+        functionNr = __intVal(nr);
+        if ((functionNr >= 0) && (functionNr < __stxNCustomFunctions__)) {
+            /*
+             * now, call the function; passing nargs and arg-vector
+             */
+            func = __stxCustomFunctions__[functionNr].func;
+            if (func) {
+                int ok;
 
-		retVal = self;
-		ok = (*func)(nargs, &retVal, __ArrayInstPtr(argArray)->a_element);
-		if (ok) {
-		    RETURN (retVal);
-		}
-		called = true;
-	    }
-	}
+                retVal = self;
+                ok = (*func)(nargs, &retVal, __ArrayInstPtr(argArray)->a_element);
+                if (ok) {
+                    RETURN (retVal);
+                }
+                called = true;
+            }
+        }
     }
 %}.
     called ifTrue:[
-	"
-	 the customFunction returned 0 (failure)
-	"
-	^ self primitiveFailed
+        "
+         the customFunction returned 0 (failure)
+        "
+        ^ self primitiveFailed
     ].
 
     "
@@ -196,11 +224,13 @@
 !
 
 callCustomFunctionNamed:name withArguments:argArray
+    "call a custom function by name with arguments from argArray"
+
     |index|
 
     index := self indexOfCustomFunctionNamed:name.
     index notNil ifTrue:[
-	^ self callCustomFunction:index withArguments:argArray
+        ^ self callCustomFunction:index withArguments:argArray
     ].
     "
      no such function exists
@@ -209,11 +239,14 @@
 
     "
      ExternalFunction callCustomFunctionNamed:'demoFunction0'
-				withArguments:#()
+                                withArguments:#()
     "
+
+    "Modified: 22.4.1996 / 18:08:09 / cg"
 !
 
 indexOfCustomFunctionNamed:functionName
+    "return the index of a named custom function"
 
 %{  /* NOCONTEXT */
 #ifndef __stxNCustomFunctions__
@@ -222,15 +255,15 @@
 #endif
 
     if (__isString(functionName)) {
-	char *nm;
-	int i;
+        char *nm;
+        int i;
 
-	nm = __stringVal(functionName);
-	for (i=0; i < __stxNCustomFunctions__; i++) {
-	   if (strcmp(__stxCustomFunctions__[i].name, nm) == 0) {
-		RETURN (__MKSMALLINT(i));
-	   }
-	}
+        nm = __stringVal(functionName);
+        for (i=0; i < __stxNCustomFunctions__; i++) {
+           if (strcmp(__stxCustomFunctions__[i].name, nm) == 0) {
+                RETURN (__MKSMALLINT(i));
+           }
+        }
     }
 %}.
     ^ nil
@@ -377,6 +410,6 @@
 !ExternalFunction class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/Attic/ExtFunc.st,v 1.5 1996-04-16 09:30:18 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Attic/ExtFunc.st,v 1.6 1996-04-22 16:14:01 cg Exp $'
 ! !
 ExternalFunction initialize!
--- a/ExternalFunction.st	Mon Apr 22 17:41:09 1996 +0200
+++ b/ExternalFunction.st	Mon Apr 22 18:14:01 1996 +0200
@@ -75,30 +75,40 @@
     Instances of this class represent external (non-Smalltalk) functions.
 
     Also, the class provides access to custom functions 
-    These custom functions enable you to call c functions even if no
-    stc is available (they are kind of what user-primitives are in ST-80).
-    You can register your own custom C-functions and relink ST/X from the
-    binaries.
+    These custom functions enable you to call c functions 
+    even if no stc compiler is available 
+    (they are kind of what user-primitives are in ST-80).
+    You can register your own custom C-functions in a private main.c
+    and relink ST/X from the binaries.
     (see the demo functions provided in main.c).
 
-    Non custom externalFunctions provide the basic low level mechanism
-    to call external C functions (as loaded dynamically by the ObjectLoader)
-    - however, this is still in construction and 
-      NOT yet published for general use.
+    If you have the stc compiler, we recommend using inline primitive
+    code: its much easier to enter, compile, debug and maintain.
+    (especially, to maintain, since the primitive code is contained
+     in the classes source/object file - while custom functions are 
+     external to the classLibraries).
 
-    For now, either use inline C-code, or use the customFunction call
-    mechanism.
+    In the furture, non custom externalFunctions will be created when
+    a non-ST shared library is loaded, and the contained C Functions will
+    be callable via those handles.
+    - however, this is still in construction and NOT yet published for 
+      general use. For now, either use inline C-code, or use the customFunction call
+      mechanism.
 "
 ! !
 
 !ExternalFunction class methodsFor:'initialization'!
 
 initialize
+    "create signals"
+
     InvalidCustomFunctionSignal isNil ifTrue:[
-	InvalidCustomFunctionSignal := ExecutionErrorSignal newSignalMayProceed:true.
-	InvalidCustomFunctionSignal nameClass:self message:#invalidCustomFunctionSignal.
-	InvalidCustomFunctionSignal notifierString:'attempt to execute unknown custom function'.
+        InvalidCustomFunctionSignal := ExecutionErrorSignal newSignalMayProceed:true.
+        InvalidCustomFunctionSignal nameClass:self message:#invalidCustomFunctionSignal.
+        InvalidCustomFunctionSignal notifierString:'attempt to execute unknown custom function'.
     ]
+
+    "Modified: 22.4.1996 / 18:08:55 / cg"
 ! !
 
 !ExternalFunction class methodsFor:'Signal constants'!
@@ -110,39 +120,57 @@
     ^ InvalidCustomFunctionSignal
 ! !
 
-!ExternalFunction class methodsFor:'custom functions'!
+!ExternalFunction class methodsFor:'calling custom functions'!
 
 callCustomFunction:nr
+    "call the custom function #nr without arguments"
+
     ^ self callCustomFunction:nr withArguments:#()
 
     "
      ExternalFunction callCustomFunction:0
      ExternalFunction callCustomFunction:999 
     "
+
+    "Modified: 22.4.1996 / 18:06:52 / cg"
 !
 
 callCustomFunction:nr with:arg
+    "call the custom function #nr with a single argument"
+
     ^ self callCustomFunction:nr withArguments:(Array with:arg)
 
     "
      ExternalFunction callCustomFunction:1 with:'hello world'
     "
+
+    "Modified: 22.4.1996 / 18:07:03 / cg"
 !
 
 callCustomFunction:nr with:arg1 with:arg2
+    "call the custom function #nr with two arguments"
+
     ^ self callCustomFunction:nr withArguments:(Array with:arg1 with:arg2)
 
     "
      ExternalFunction callCustomFunction:2 with:(Float pi) with:1.0
     "
+
+    "Modified: 22.4.1996 / 18:07:11 / cg"
 !
 
 callCustomFunction:nr with:arg1 with:arg2 with:arg3
+    "call the custom function #nr with three arguments"
+
     ^ self callCustomFunction:nr 
-		withArguments:(Array with:arg1 with:arg2 with:arg3)
+                withArguments:(Array with:arg1 with:arg2 with:arg3)
+
+    "Modified: 22.4.1996 / 18:07:18 / cg"
 !
 
 callCustomFunction:nr withArguments:argArray
+    "call the custom function #nr with arguments from argArray"
+
     |retVal called|
 
 %{
@@ -154,33 +182,33 @@
 
     called = false;
     if (__isSmallInteger(nr) && __isArray(argArray)) {
-	int nargs = __arraySize(argArray);
-	int functionNr;
+        int nargs = __arraySize(argArray);
+        int functionNr;
 
-	functionNr = __intVal(nr);
-	if ((functionNr >= 0) && (functionNr < __stxNCustomFunctions__)) {
-	    /*
-	     * now, call the function; passing nargs and arg-vector
-	     */
-	    func = __stxCustomFunctions__[functionNr].func;
-	    if (func) {
-		int ok;
+        functionNr = __intVal(nr);
+        if ((functionNr >= 0) && (functionNr < __stxNCustomFunctions__)) {
+            /*
+             * now, call the function; passing nargs and arg-vector
+             */
+            func = __stxCustomFunctions__[functionNr].func;
+            if (func) {
+                int ok;
 
-		retVal = self;
-		ok = (*func)(nargs, &retVal, __ArrayInstPtr(argArray)->a_element);
-		if (ok) {
-		    RETURN (retVal);
-		}
-		called = true;
-	    }
-	}
+                retVal = self;
+                ok = (*func)(nargs, &retVal, __ArrayInstPtr(argArray)->a_element);
+                if (ok) {
+                    RETURN (retVal);
+                }
+                called = true;
+            }
+        }
     }
 %}.
     called ifTrue:[
-	"
-	 the customFunction returned 0 (failure)
-	"
-	^ self primitiveFailed
+        "
+         the customFunction returned 0 (failure)
+        "
+        ^ self primitiveFailed
     ].
 
     "
@@ -196,11 +224,13 @@
 !
 
 callCustomFunctionNamed:name withArguments:argArray
+    "call a custom function by name with arguments from argArray"
+
     |index|
 
     index := self indexOfCustomFunctionNamed:name.
     index notNil ifTrue:[
-	^ self callCustomFunction:index withArguments:argArray
+        ^ self callCustomFunction:index withArguments:argArray
     ].
     "
      no such function exists
@@ -209,11 +239,14 @@
 
     "
      ExternalFunction callCustomFunctionNamed:'demoFunction0'
-				withArguments:#()
+                                withArguments:#()
     "
+
+    "Modified: 22.4.1996 / 18:08:09 / cg"
 !
 
 indexOfCustomFunctionNamed:functionName
+    "return the index of a named custom function"
 
 %{  /* NOCONTEXT */
 #ifndef __stxNCustomFunctions__
@@ -222,15 +255,15 @@
 #endif
 
     if (__isString(functionName)) {
-	char *nm;
-	int i;
+        char *nm;
+        int i;
 
-	nm = __stringVal(functionName);
-	for (i=0; i < __stxNCustomFunctions__; i++) {
-	   if (strcmp(__stxCustomFunctions__[i].name, nm) == 0) {
-		RETURN (__MKSMALLINT(i));
-	   }
-	}
+        nm = __stringVal(functionName);
+        for (i=0; i < __stxNCustomFunctions__; i++) {
+           if (strcmp(__stxCustomFunctions__[i].name, nm) == 0) {
+                RETURN (__MKSMALLINT(i));
+           }
+        }
     }
 %}.
     ^ nil
@@ -377,6 +410,6 @@
 !ExternalFunction class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/ExternalFunction.st,v 1.5 1996-04-16 09:30:18 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/ExternalFunction.st,v 1.6 1996-04-22 16:14:01 cg Exp $'
 ! !
 ExternalFunction initialize!