Search code examples
programming-languagesinterfacesmalltalk

How can I run external code from Squeak environment?


As far as I know, the Squeak environment is quite isolated from the rest of the operating system. However, I'm looking for a way to execute external code, which will be written in a different language, from within it. We need this to connect to an old code base.

Is this possible? Which options do I have?


Solution

  • You have basically 3 options:

    1. Write a plugin: you can extend the Squeak VM with modules containing C functions called "primitives", which then can be used from Squeak code. Primitives is how Squeak code interfaces with the outside world (e.g. for accessing files or the internet or play sound). You can link your plugin with any library, so you can interface to any language that has C bindings.
    2. Use FFI: The Foreign Function Interface is a generic way for calling C functions from libraries. This is harder to get working correctly on multiple platforms, but you do not need a C compiler as when building a plugin, and you do not need to distribute the plugin to your users.
    3. Use OSProcess: this package lets you call an external executable and communicate via stdin/stdout.

    Writing a plugin is the most flexible and high-performance option, but not trivial. OSProcess is simplest, and FFI in the middle.