|
Class: ExternalFunction
Object
|
+--ExecutableFunction
|
+--ExternalFunction
|
+--ExternalFunctionCallback
|
+--ExternalLibraryFunction
- Package:
- stx:libbasic
- Category:
- System-Support-External Memory
- Version:
- rev:
1.34
date: 2022/03/24 07:52:26
- user: cg
- file: ExternalFunction.st directory: libbasic
- module: stx stc-classLibrary: libbasic
Instances of this class represent external (non-Smalltalk) functions.
(Obsolete) Custom Functions:
This class also provides access to custom functions.
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).
Notice, that custom functions are ugly and inflexible.
They are to be considered obsolete and support for them will vanish.
If you have the stc compiler, we recommend using either inline primitive
code or the new external function call interface which is based upon libffi.
Both are 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).
Non custom externalFunctions are created, when a non-ST shared library is loaded,
and returned by the ObjectFileHandles>>getFunction: method.
The C functions contained in that lib are callable (instances of myself)
with the call / callWith: methods.
ST-arguments are converted to C as follows:
ST class C argument
------------------------------
SmallInteger int
LargeInteger int (must be 4-byte unsigned largeInteger)
String char *
Symbol char *
Character int
ExternalBytes char *
ExternalAddress char *
ExternalFunction char *
FloatArray float *
DoubleArray double *
ByteArray char *
ShortFloat float
true 1
false 0
The returned value is converted to an unsigned integer (smallInteger or largeInteger).
Notice, that no doubles can be passed; the reason is that the calling
conventions (on stack, in registers, in FPU registers etc.) are so different among
machines (and even compilers), that a general solution is not possible (difficult)
to program here. To pass doubles, either use shortFloats, or pack them into a DoubleArray.
For functions with up to 2 double arguments, specialized call methods are provided.
Sorry for that inconvenience.
- This is still in construction and NOT yet published for
general use. For now, use inline C-code.
copyrightCOPYRIGHT (c) 1994 by Claus Gittinger
All Rights Reserved
This software is furnished under a license and may be used
only in accordance with the terms of that license and with the
inclusion of the above copyright notice. This software may not
be provided or otherwise made available to, or used by, any
other person. No title to or ownership of the software is
hereby transferred.
Signal constants
-
invalidCustomFunctionSignal
-
return the signal raised when a non existent custom function is
called for.
calling custom functions
-
callCustomFunction: nr
-
call the custom function #nr without arguments.
See main.c for examples.
Usage example(s):
ExternalFunction callCustomFunction:0
ExternalFunction callCustomFunction:999
|
-
callCustomFunction: nr with: arg
-
call the custom function #nr with a single argument.
See main.c for examples.
Usage example(s):
ExternalFunction callCustomFunction:1 with:'hello world'
|
-
callCustomFunction: nr with: arg1 with: arg2
-
call the custom function #nr with two arguments.
See main.c for examples.
Usage example(s):
ExternalFunction callCustomFunction:2 with:(Float pi) with:1.0
|
-
callCustomFunction: nr with: arg1 with: arg2 with: arg3
-
call the custom function #nr with three arguments.
See main.c for examples.
-
callCustomFunction: nr withArguments: argArray
-
call the custom function #nr with arguments from argArray.
See main.c for examples.
Usage example(s):
ExternalFunction callCustomFunction:2 withArguments:#(1.0 1.0)
ExternalFunction callCustomFunction:999 withArguments:#(1.0 1.0)
|
-
callCustomFunctionNamed: name withArguments: argArray
-
call a custom function by name with arguments from argArray
Usage example(s):
ExternalFunction callCustomFunctionNamed:'demoFunction0'
withArguments:#()
|
-
indexOfCustomFunctionNamed: functionName
-
return the index of a named custom function
Usage example(s):
ExternalFunction indexOfCustomFunctionNamed:'demoFunction0'
ExternalFunction indexOfCustomFunctionNamed:'fooBar'
|
initialization
-
initialize
-
create signals
queries
-
isBuiltInClass
-
return true if this class is known by the run-time-system.
Here, true is returned for myself, false for subclasses.
accessing
-
moduleHandle
-
return the function's moduleHandle
(nil if not loaded dynamically)
-
name
-
return the function's name
function calling
-
call
-
call the underlying C function, passing no argument.
The return value is interpreted as an integer
(and must be converted to an externalBytes object,
if it is a pointer to something).
DANGER alert: This is an unprotected low-level entry.
Not for normal application usage.
-
callByRefWith: arg
-
call the underlying C function, passing a single argument by reference.
The pointer of the argument is passed. Use this if you want to call a
function with call-by-refernece semantics, like in fortran.
The argument arg is converted to a corresponding C data type,
as defined in the convertST_to_C() function.
The return value is interpreted as an integer
(and must be converted to an externalBytes object,
if it is a pointer to something).
DANGER alert: This is an unprotected low-level entry.
Not for normal application usage.
-
callByRefWith: arg with: arg2
-
call the underlying C function, passing two args.
The pointer of the arguments are passed. Use this if you want to call a
function with call-by-refernece semantics, like in fortran.
The arguments are converted to a corresponding C data type,
as defined in the convertST_to_C() function.
The return value is interpreted as an integer
(and must be converted to an externalBytes object,
if it is a pointer to something).
DANGER alert: This is an unprotected low-level entry.
Not for normal application usage.
-
callByRefWith: arg with: arg2 with: arg3
-
call the underlying C function, passing three args.
The pointer of the arguments are passed. Use this if you want to call a
function with call-by-refernece semantics, like in fortran.
The arguments are converted to a corresponding C data type,
as defined in the convertST_to_C() function.
The return value is interpreted as an integer
(and must be converted to an externalBytes object,
if it is a pointer to something).
DANGER alert: This is an unprotected low-level entry.
Not for normal application usage.
-
callByRefWithArguments: argArray
-
call the underlying C function, passing up to 10 arguments by reference.
The arguments are converted to a corresponding C data type,
as defined in the convertST_to_C() function.
The return value is interpreted as an integer
(and must be converted to an externalBytes object,
if it is a pointer to something).
DANGER alert: This is an unprotected low-level entry.
Not for normal application usage.
-
callO
-
call the underlying C function, passing no argument.
The return value must be a valid object.
DANGER alert: This is an unprotected low-level entry.
Not for normal application usage.
-
callOWith: arg
-
call the underlying C function, passing a single object argument.
The return value must be a valid object.
DANGER alert: This is an unprotected low-level entry.
Not for normal application usage.
-
callOWith: arg1 with: arg2
-
call the underlying C function, passing two args.
The return value must be a valid object.
DANGER alert: This is an unprotected low-level entry.
Not for normal application usage.
-
callOWith: arg1 with: arg2 with: arg3
-
call the underlying C function, passing three args.
The return value must be a valid object.
DANGER alert: This is an unprotected low-level entry.
Not for normal application usage.
-
callWith: arg
-
call the underlying C function, passing a single argument.
The argument arg is converted to a corresponding C data type,
as defined in the convertST_to_C() function.
The return value is interpreted as an integer
(and must be converted to an externalBytes object,
if it is a pointer to something).
DANGER alert: This is an unprotected low-level entry.
Not for normal application usage.
-
callWith: arg1 with: arg2
-
call the underlying C function, passing two args.
The arguments are converted to a corresponding C data type,
as defined in the convertST_to_C() function.
The return value is interpreted as an integer
(and must be converted to an externalBytes object,
if it is a pointer to something).
DANGER alert: This is an unprotected low-level entry.
Not for normal application usage.
-
callWith: arg1 with: arg2 with: arg3
-
call the underlying C function, passing three args.
The arguments are converted to a corresponding C data type,
as defined in the convertST_to_C() function.
The return value is interpreted as an integer
(and must be converted to an externalBytes object,
if it is a pointer to something).
DANGER alert: This is an unprotected low-level entry.
Not for normal application usage.
-
callWithArguments: argArray
-
call the underlying C function, passing up to 10 arguments.
The arguments are converted to a corresponding C data type,
as defined in the convertST_to_C() function.
The return value is interpreted as an integer
(and must be converted to an externalBytes object,
if it is a pointer to something).
DANGER alert: This is an unprotected low-level entry.
Not for normal application usage.
-
callWithDouble: aFloatArg returnsDouble: doubleFlag
-
call the underlying C function, passing a single double argument.
The returnsDouble flag specifies if the returnValue is a double; if false,
an integer returnValue is assumed.
-
callWithDouble: aFloatArg1 withDouble: aFloatArg2 returnsDouble: doubleFlag
-
call the underlying C function, passing two double arguments.
The returnsDouble flag specifies if the returnValue is a double; if false,
an integer returnValue is assumed.
printing & storing
-
printOn: aStream
-
append a printed representation of the receiver to aStream
private-loader access
-
invalidate
-
-
setModuleHandle: aHandle
-
set the moduleHandle.
This is a private interface for the objectFileLoader; not for public use.
-
setName: aString moduleHandle: aHandle
-
set the name & moduleHandle.
This is a private interface for the objectFileLoader; not for public use.
see a sample demo c file in doc/coding/cModules;
compile and link (shared) it to an object module.
Load it into the system:
handle := ObjectFileLoader loadDynamicObject:'demo1.o'.
get a C-function (an instance of ExternalFunction):
f := handle getFunction:'function1'.
call it:
f callWith:999
|