[View]  [Edit]  [Lock]  [References]  [Attachments]  [History]  [Home]  [Changes]  [Search]  [Help] 

[pi8] Installing FFI support in Rasperry Pi 3

  1. Install S8 (ensure the SystemServer is working)
  2. open a console and go to the folder where you start S8
  3. Install node-ffi with
    cd ~/Desktop/node
    npm install ffi
  4. start S8
    node n8.snapshot.js

Accessing the System Server to check we can load FFI

  1. Open a Workspace and connect to the server (user the URL shown by SystemServer in the console)
  2. Load the library evaluating with showIt
    JS @> (self require: #ffi)
    The API details of the library will be returned if all has worked as expected

Testing a simple case

Evaluate in the connected workspace the following expression
| ffi libm |
ffi := self require: #ffi.
libm := ffi #Library: #libm value: (#ceil -> #(double #(double))) json.
libm #ceil: 1.5
The result must be number 2

You can also access just functions in the current process e.g.:
| ffi current |
ffi := self require: #ffi.
current := ffi #Library: nil json value: (#atoi -> #(int #(string))) json.
current #atoi: #1234
The result must be number 1234

Using the node-ffi framework

The node-ffi framework can be loaded in the image (loading module node-ffi.st.js) to access the framework from S8 wrappers.

To load the framework dynamically in your Raspberry Pi, evaluate the following expression from a connected workspace
Smalltalk current eval: 'build/node/library/node-ffi/node-ffi.st.js' fileContents
Note that the previous code will load the binary version of the framework, so after loading you can perform framework tests in your pie e.g. evaluating
SwikiCodeRobot @> #(test S8FFI)


References


Notes

Enter the following commands to build node-ffi from source files
git clone git://github.com/node-ffi/node-ffi.git
cd node-ffi
node-gyp rebuild