Communicating with other languages (or embedding squeak)

David T. Lewis lewis at mail.msen.com
Mon Oct 11 22:13:35 UTC 2004


On Fri, Oct 08, 2004 at 10:23:23AM -0400, Daniel B. Faken wrote:
> 
>   I need to control external processes (on *nix, but possibly other 
> platforms in the future).  I would like to do so by embedding an 
> interpretable (i.e. not compiled) language into the external programs.
> My squeak program needs to send & receive to/from them securely and with
> decent efficiency -- e.g. via FIFOs.
>   The ideal thing would be to embed squeak into them, extending it to have 
> app-specific functions (open a new document, rotate a molecule, etc.).  
> But from what I can gather from the mailing list and swiki, reentrancy is
> not implemented in the FFI, and getting the footprint below (e.g.) 1MB is
> problematic (an issue for me since many applications could potentially be
> using the embedded squeak simultaneously - I don't want to add 13MB to 
> each one).
>   I've looked at languages like Io, TCL, Lua, etc. but haven't been happy
> with any of them.. (though I have implemented primitive bridges for TCL 
> and Io).

Hi Daniel,

If you want to control external processes that have (for example) embedded
tcl interpreters, you can do this from Squeak on Linux using the CommandShell
package and OSProcess, both or which are available on SqueakMap. In particular,
the class PipeableOSProcess implements a connected external OS process with
stdin, stdout, and stderr available as streams to Squeak. For example, to
start a simple wish script, you can do something like this:

  | wish |
  wish :=  PipeableOSProcess command: '/usr/bin/wish'.
  [wish
    exec: 'button .b1 -text "This is button b1"';
    exec: 'button .b2 -text "This is button b2"';
    exec: 'button .exit -text Exit -command exit';
    exec: 'pack .b1 .b2 .exit'] fork.
  wish inspect

In this example, you are writing tk/tcl commands to the stdin of the external
process running the /usr/bin/wish program. An instance of PipeableOSProcess
serves as a proxy for the running /usr/bin/wish program, and provides streams
connected to stdin, stdout and stderr of the wish interpreter.

You also described wanting to control app-specific functions from Squeak
directly. If the "functions" are compiled programs that run in independent
OS processes, you can easily start them from Squeak and receive notification
by means of a Squeak semaphore when they exit (along with program exit status).
If you take this approach, you can use Squeak itself as the "script" language.
You can find some examples in the "command scripting" method category of
CommandShell. For example, you can do:

  CommandShell new
    if: 'who'
    then: ['the /usr/bin/who command succeeded']
    else: ['the /usr/bin/who command failed']

I'm afraid that some of my example methods in OSProcess and CommandShell
have acquired some bit rot of late, but hopefully they are still understandable.
Feel free to ask any specific questions on this list or off-list directly to me.

HTH,
Dave




More information about the Squeak-dev mailing list