PlatformFunction protocols
The address of a PlatformFunction is not looked up until required (for example, when calling it). Looking up the address is referred to as binding. A PlatformFunction can also be unbound by the system, meaning that it must be bound again before being called.
Instance methods: accessing
The get methods are listed below. For every get method, there is a corresponding set method.
address
Answer the address (a positive Integer) of the receiver. If the receiver is not already bound, bind it. If the binding fails, a walkback occurs.
callingConvention
Answer the calling convention (a Symbol) of the receiver.
functionNumber
If the receiver is a numbered function, answers the number (a positive Integer). Otherwise, answers nil.
library
If the receiver resides in a shared library, answers the appropriate PlatformLibrary object. Otherwise, answers nil.
name
If the receiver is a named function, answers the function name (a String). Otherwise, answers nil.
parameterTypes
Answer an array of the receiver's parameter types (Symbols).
returnType
Answer the Symbol describing the return type of the receiver.
Instance methods: calling
call
Call the receiver and answer the result of the call. If the return type is void, answer the receiver. If the receiver cannot be bound or a parameter cannot be converted, a walkback occurs.
callWith:
Call the receiver with the given argument. Answer the result of the call, or if the return type is void, answer the receiver. If the receiver cannot be bound or a parameter cannot be converted, a walkback occurs.
callWith:with:
Call the receiver with the given arguments. Answer the result of the call, or if the return type is void, answers the receiver. If the receiver cannot be bound or a parameter cannot be converted, a walkback occurs.
callWith:with:...with:
Call the receiver with the given arguments. The maximum number of arguments is 32. Answer the result of the call, or if the return type is void, answer the receiver. If the receiver cannot be bound or a parameter cannot be converted, a walkback occurs.
callWithArguments:
Call the receiver with the given array arguments. Answer the result of the call, or if the return type is void, answer the receiver. If the receiver cannot be bound or a parameter cannot be converted, a walkback occurs.
callWithArguments:returnValue:
Call the receiver with the given array arguments. Store the result of the call into the returnValue which is an <OSStructure> instance. If the receiver cannot be bound or a parameter cannot be converted or the returnValue is not valid, a walkback occurs.
Class methods: instance creation
callingConvention:function:library:parameterTypes:returnType:
Answer a new PlatformFunction with the given parameters. The callingConvention: must be a string or symbol. The function: can be a positive Integer or a String. The library: is the name of the shared library where the function is stored. It can be a String or nil. parameterTypes: is an array of type names (Strings or Symbols). The returnType: is a single type name (a String or Symbol).
Note:
If the library is given as nil, the function must be a String. The function is looked up in the user primitive table instead of in a shared library. The String is the name of the user primitive. The function that is called is not a user primitive; it is a normal C function.
callingConvention:address:parameterTypes:returnType:
Answer a new PlatformFunction with the given parameters. The callingConvention:, parameterTypes:, and returnType: are the same as above. The address: is a positive Integer. Use this method to create a PlatformFunction for a function that is not in a shared library but whose address is available by some other means (for example, returned by an operating system call). A PlatformFunction created in this manner has its address set to zero when the image starts.
The following table shows the mapping between the PlatformFunction calling convention and the platform-specific C compiler calling convention.
| | |
'c' ‘pascal’ | __stdcall | (none) |
'cdecl' | __cdecl | NA |
'thisCall' | __thiscall | NA |
Last modified date: 11/05/2019