RSS Feed

Lisp Project of the Day

scriptl

You can support this project by donating at:

Donate using PatreonDonate using Liberapay

Or see the list of project sponsors.

scriptlcommandlinerpc

Documentation😀
Docstrings🥺
Tests 🥺
Examples😀
RepositoryActivity🥺
CI 🥺

This system implements a very interesting idea. It makes it very easy to call any lisp function from the command line.

The cool part of this story is the ability to quickly hack on your functions in the Emacs while calling them from the command line. This can be especially useful in many cases like writing a plugin for the BitBar.

ScriptL consists of three parts:

  • a server, running in your lisp image
  • a client binary for passing parameters to the server and returning results
  • a thin wrapper for each command.

Here is a minimal example to show you how it works.

The first command starts the server. Second, defines the usual function and third creates a shell script "hello-world" in the current directory:

POFTHEDAY> (scriptl:start)

POFTHEDAY> (defun hello-world (&optional (name "Anonymous"))
             (format t "Hello, ~A!~%" name))

POFTHEDAY> (scriptl:make-script "hello-world"
                                'hello-world)

Now let's switch to the command line and call our function:

[poftheday] ./hello-world
Hello, Anonymous!

[poftheday] ./hello-world Bob
Hello, Bob!

Here is how the wrapper looks like under the hood:

[poftheday] cat hello-world
#!/bin/sh
SCRIPTLCOM="./.qlot/dists/quicklisp/software/
            scriptl-20180228-git/src/scriptlcom/src/scriptlcom"
FUNCTION="POFTHEDAY::HELLO-WORLD"
ERRORS="COMMON-LISP::NIL"
SYSTEM=""

$SCRIPTLCOM --sl-version 2 -E "$ERRORS" -l "$SYSTEM" -f "$FUNCTION" -- "$@"

As you can see, it calls scriptlcom binary, written in C.

The ScriptL server can also be started on a remote machine, but the documentation does not cover this setup.

Playing with this system I recall where I seen a similar way of calling the server from the command line. It is possible with CL-Gearman, reviewed in post number 0095. Gearman has a command-line client but, is more suitable for server-server communication.


Brought to you by 40Ants under Creative Commons License