What is the FFI Squeak syntax in the new Squeak (5.0)

I am trying to use the Squeak external function interface. All the information I could find does not seem to apply to the new Squeak 5.0, because when I try for example:

add: a to: b " ( int ) add (int a, int b) ; " < cdecl: int 'add' ( int a, int b ) module: 'mydll'> ^ self externalCallFailed 

which is obtained from this page :

 apiInvalRect: aRect " ( void ) InvalRect (const Rect &star; badRect ) ; " < cdecl: void 'InvalRect' ( MacRect ) module: 'InterfaceLib'> ^ self externalCallFailed. 

then I get the error that it expects > immediately after < .

(I use Squeak 5.0 for Windows with SqueakFFIPrims.bundle in its resource directory.)

+5
source share
1 answer

First you need to set FFI to the image via Monticello.

The FFI package is located at http://source.squeak.org/FFI.html

You need to install "FFI-Pools" first, then "FFI-Kernel". Then you can download "FFI-Tests" and "FFI-Example".

Once FFI is installed on the image, the correct syntax will be something like this:

 add: a to: b " ( int ) add (int a, int b) ; " <cdecl: long 'add' ( long long ) module: 'mydll'> ^ self externalCallFailed 

You do not specify parameter names - they implicitly occupy the same position as the smalltalk method.

You have to replace int with long ones - this is the same on supported 32-bit platforms.

EDIT to download the FFI package to Squeak, you can enter and execute (do this) in the workspace:

 (Installer repository: 'http://source.squeak.org/FFI') install: 'FFI-Pools'; install: 'FFI-Kernel'; install: 'FFI-Tests'; install: 'FFI-Examples'. 
+3
source

Source: https://habr.com/ru/post/1233963/


All Articles