Entry points
VA Smalltalk allows other languages to call Smalltalk through the EsEntryPoint mechanism. An EsEntryPoint is an object that prototypes a function in another language such as C. An EsEntryPoint contains the Smalltalk receiver and selector as well as the types of the parameters and any return value.
For example, to create an EsEntryPoint for the WindowProc function in Windows, you can use the following code from the class OSEventManager:
"VA Smalltalk 32-bit"
initializePlatformWindowProc32
"Create the 32-bit Smalltalk window procedure."
WindowProc := EsEntryPoint
receiver: self
selector: #windowProc:msg:with:with:
callingConvention: 'c'
arrayBased: false
parameterTypes: #(#pointer #uint32 #uint32 #int32)
returnType: #int32.
WindowProc failAddress: DefWindowProc address.
 
"VA Smalltalk 64-bit"
initializePlatformWindowProc64
"Create the 64-bit Smalltalk window procedure."
WindowProc := EsEntryPoint
receiver: self
selector: #windowProc:msg:with:with:
callingConvention: 'c'
arrayBased: false
parameterTypes: #(#pointer #uint32 #uint64 #int64)
returnType: #int64.
WindowProc failAddress: DefWindowProc64 address.
 
initializePlatformWindowClass
"Private - Get the standard ENVY/Smalltalk window
procedure and register the window class in the OS."
 
| lpszClassName lpWndClass result |
 
"Create the Smalltalk window procedure.
This will initialize the WindowProc class variable"
System is64BitVM
ifTrue: [self initializePlatformWindowProc64]
ifFalse: [self initializePlatformWindowProc32].
 
"Register the Smalltalk window procedure."
(WindowClass == nil or: [WindowClass isInFixedSpace not])
ifTrue: [WindowClass := 'WINDOWPROC' asPSZ makeFixed].
lpWndClass := OSWndclass new.
lpszClassName := OSStringZ reference: WindowClass.
result :=
lpWndClass
style: (CsBytealignwindow bitOr: CsDblclks);
lpszClassName: lpszClassName;
lpfnWndProc: WindowProc address;
hCursor: (HInstanceNull loadCursor: IdcArrow);
hIcon: (HInstance loadIcon: DefaultIconID);
hInstance: HInstance;
registerClass.
^result
To use an EsEntryPoint, create it and send it the message address. The result is an integer that can be passed out to a PlatformFunction that requires a function pointer as a parameter. When the external language calls the function pointer, VA Smalltalk converts the parameters into Smalltalk objects and sends the message designated by the receiver and selector of the EsEntryPoint. The receiver parameter can be any Smalltalk object. The selector parameter must be a Symbol. parameterTypes is an array of type names and returnType is a single type name. The callingConvention parameter must be a string that is one of the valid VA Smalltalk calling conventions. For details about platform-specific calling conventions, see Platform requirements.
There are two kinds of EsEntryPoints, depending on the value of arrayBased parameter when an EsEntryPoint is created. If arrayBased is false, the selector must take the same number of parameters as the number of parameters in the parameterTypes array; that is, one per external language parameter. If arrayBased is true, the selector must take one parameter, which is an array of all the parameters.
Note:
When using an EsEntryPoint, you do not need to make any of the objects (the receiver, selector, or the EsEntryPoint itself) fixed.
Last modified date: 08/10/2017