Fundamentals of Computer Science 1 (CS151 2003S)

Writing Script-Fu Procedures

Summary:

Contents:

SIOD vs. Real Scheme

Script-Fu is based on SIOD, a small but efficient implementation of Scheme. Unfortunately, SIOD varies in many ways from pure Scheme. While a few of those variantions have little impact, some have great impact. You can read more about SIOD at http://people.delphi.com/gjc/siod.html.

Arrays vs. Vectors

One big difference is that SIOD does not provide vectors. Instead, it provides things called arrays. Arrays are a lot like vectors in that they are mutable and provide indexed access. Arrays differ in that you typically specify the "kind" of thing that goes in an array (e.g., real numbers (which programmers call floats), integers, strings).

SIOD provides a few basic array procedures, including ...

My library provides a float-array procedure that works a lot like the standard list and vector procedures that you know and love. That is, you give it as many parameters as you like, and it builds an array of the appropriate size.

Once you've written a few useful Script-Fu procedures, you can actually add them to the Gimp menus (scary, isn't it). You need to follow two or three simple steps to get them added:

1. Write Scheme code that tells the Gimp to add a procedure to the menu. Here, you need to tell the Gimp what parameters your procedure takes so that it can ask the user for those parameters.

2. Put the Scheme code in a place the Gimp can find it. Typically, you'll put your Scheme code in /home/username/.gimp/scripts. (Yes, the period before the .gimp is important.) You'll only have to do this once per script.

3. Tell the Gimp that you've added the script by selecting Refresh from the Script-Fu submenu of the Xtns menu. (You should only have to do this when you add or modify the script in the middle of a session. In the future, the Gimp should load your script automatically.)

Steps 2 and 3 are straightforward, so let's consider the first step in more detail. You add a procedure with the script-fu-register procedure. That procedure takes a large number of parameters.

For each parameter for your procedure, you'll need three parameters to script-fu-register

Disclaimer: I usually create these pages on the fly, which means that I rarely proofread them and they may contain bad grammar and incorrect details. It also means that I tend to update them regularly (see the history for more details). Feel free to contact me with any suggestions for changes.

This document was generated by Siteweaver on Tue May 6 09:31:07 2003.
The source to the document was last modified on Sun Mar 30 22:17:08 2003.
This document may be found at http://www.cs.grinnell.edu/~rebelsky/Courses/CS151/2003S/Readings/script-fu-procs.html.

You may wish to validate this document's HTML ; Valid CSS! ; Check with Bobby

Samuel A. Rebelsky, rebelsky@grinnell.edu