Gimp/plug-ins/script-fu/libscriptfu
Jehan f92f7d425c plug-ins: new named argument syntax in Script-Fu.
This syntax is now the official syntax for non-core PDB procedures.

I.e. that while core procedures will still use ordered arguments (e.g.:
`(gimp-image-get-layers 1)`), plug-in PDB procedures called from
Script-Fu will have named arguments in any order.

Say for instance that you want to call python-fu-foggify from Script-Fu.
Whereas we used to run:

> (python-fu-foggify RUN-NONINTERACTIVE 1 (car (gimp-image-get-layers 1)) "Clouds" '(50 4 4) 1.0 50.0)

Now we should call:

> (python-fu-foggify #:image 1 #:drawables (car (gimp-image-get-layers 1)) #:opacity 50.0 #:color '(50 4 4))

Now we can note:

* Every argument is preceded by a #:label which is the argument name.
  This makes these calls much more readable (some plug-in procedures can
  have dozen of arguments and these end up as list of integers, floats
  and strings, which are hard to read and hard to debug) and semantic.
* Order doesn't matter anymore. For instance here, I put #:opacity
  before #:color.
* As a direct consequence, we can drop any argument which we wish to
  keep with default value. E.g. in the old style, we had to put the
  #:run-mode, #:name ("Clouds") and #:turbulence (1.0) because we were
  changing the last argument #:opacity (50.0). Now we can drop all 3
  default arguments.

Having non-ordered argument is in fact the starter of this feature,
because it is already the case for calling PDB procedures in the libgimp
API (and therefore in all GIR bindings). By saying that the order of PDB
procedures is not part of the API, we actually allow to add arguments
and even to reorder them in the future without breaking existing scripts
in the 3.0 series.

This became even more serious when I was considering to make the generic
metadata arguments public. Since they are appended to the end, after all
plug-in-specific arguments, if I do this, adding any argument in an
export plug-in would break order. It won't matter anymore!

Note that it doesn't matter for core PDB procedures (where this syntax
is not used) because these are also C functions and therefore order and
number of arguments matter anyway. Also these don't have dozens of
arguments.

As a helper for Script-Fu developer, in particular as we already
released 2 RCs and therefore some people already started to port their
scripts, the old syntax will still work yet will produce a warning
showing how to call the same thing with the new syntax. For instance,
with the above first call, the warning will be:

> (script-fu:2059912): scriptfu-WARNING **: 22:54:47.507: Calling Plug-In PDB procedures with arguments as an ordered list is deprecated.
> Please use named arguments: (python-fu-foggify #:run-mode 1 #:image 1 #:drawables (2) #:name "Clouds" #:color '(50 4 4) #:turbulence 1.000000 #:opacity 50.000000)

Note that the argument name syntax is coming from the Racket scheme
variant: https://docs.racket-lang.org/arguments/index.html

Common Lisp has a similar syntax, either with just a colon, or also a
sharp + colon (it's unclear to me the difference, something about
interned vs. uninterned symbols).
After discussion with Liam on IRC, we decided to go with the #: syntax
of Racket.
2025-01-20 00:01:23 +01:00
..
ftx Fix spelling errors found with codespell 2025-01-04 15:11:03 +00:00
tinyscheme plug-ins: new named argument syntax in Script-Fu. 2025-01-20 00:01:23 +01:00
meson.build ScriptFu: fix #10698 and other issues with script progress 2024-04-08 11:27:13 -04:00
README
scheme-marshal-return.c app, libgimp*, pdb, plug-ins: rename various public API name s/float/double/. 2024-11-02 15:00:03 +01:00
scheme-marshal-return.h ScriptFu: extract function marshall_pdb_return 2023-09-12 15:02:15 +00:00
scheme-marshal.c plug-ins: new named argument syntax in Script-Fu. 2025-01-20 00:01:23 +01:00
scheme-marshal.h plug-ins: new named argument syntax in Script-Fu. 2025-01-20 00:01:23 +01:00
scheme-wrapper.c plug-ins: new named argument syntax in Script-Fu. 2025-01-20 00:01:23 +01:00
scheme-wrapper.h ScriptFu: fix #10307 plugin call display not effective 2024-04-25 12:51:00 +00:00
script-fu-arg.c plug-ins: remove GIMP_PARAM_NO_VALIDATE for resource arguments. 2025-01-14 00:49:33 +01:00
script-fu-arg.h libgimp, plug-ins: make generic gimp_procedure_add_argument() private. 2024-07-06 14:44:45 +02:00
script-fu-color.c ScriptFu: fix #10978 handling of color 2024-10-17 18:45:51 +00:00
script-fu-color.h plug-ins: script-fu is now GimpRGB-free. 2024-04-20 12:06:41 +02:00
script-fu-command.c extensions, libgimp, plug-ins: remove n_drawables arg from GimpImageProcedure's… 2024-10-28 22:08:45 +01:00
script-fu-command.h extensions, libgimp, plug-ins: remove n_drawables arg from GimpImageProcedure's… 2024-10-28 22:08:45 +01:00
script-fu-compat.c ScriptFu: add compatibility scripts for third party scripts 2024-10-25 13:56:36 +00:00
script-fu-compat.h
script-fu-dialog.c ScriptFu: show and hide Dock icon for extension-script-fu 2024-12-17 15:18:50 +00:00
script-fu-dialog.h extensions, libgimp, plug-ins: remove n_drawables arg from GimpImageProcedure's… 2024-10-28 22:08:45 +01:00
script-fu-enums.h ScriptFu: fix 8463 obsolete SF-VALUE 2024-09-27 06:41:29 -04:00
script-fu-errors.c ScriptFu: cleanup some debug statements 2024-12-15 14:04:16 +00:00
script-fu-errors.h ScriptFu: enhance error messages for range errors in calls to PDB 2024-09-20 10:58:50 +00:00
script-fu-interface.c ScriptFu: show and hide Dock icon for extension-script-fu 2024-12-17 15:18:50 +00:00
script-fu-interface.h ScriptFu: fix #10698 and other issues with script progress 2024-04-08 11:27:13 -04:00
script-fu-intl.h
script-fu-lib.c ScriptFu: move init scripts to separate directory /scripts/scriptfu-init 2024-10-25 13:56:36 +00:00
script-fu-lib.h ScriptFu: move init scripts to separate directory /scripts/scriptfu-init 2024-10-25 13:56:36 +00:00
script-fu-proc-factory.c Issue #8744: refactor overdependence on gimpui.h 2022-10-15 15:17:08 +00:00
script-fu-proc-factory.h ScriptFu: Add script-fu-interpreter akin to other interpreters 2022-06-30 13:39:45 +00:00
script-fu-progress.c ScriptFu: fix #10698 and other issues with script progress 2024-04-08 11:27:13 -04:00
script-fu-progress.h ScriptFu: fix #10698 and other issues with script progress 2024-04-08 11:27:13 -04:00
script-fu-regex.c
script-fu-regex.h
script-fu-register.c plug-ins: new named argument syntax in Script-Fu. 2025-01-20 00:01:23 +01:00
script-fu-register.h ScriptFu: add Scheme language function script-fu-register-regular 2024-09-27 14:35:50 +00:00
script-fu-resource.c ScriptFu: fix defaults for script args of type Resource 2024-09-17 12:06:37 +00:00
script-fu-resource.h ScriptFu: fix defaults for script args of type Resource 2024-09-17 12:06:37 +00:00
script-fu-run-func.c extensions, libgimp, plug-ins: remove n_drawables arg from GimpImageProcedure's… 2024-10-28 22:08:45 +01:00
script-fu-run-func.h extensions, libgimp, plug-ins: remove n_drawables arg from GimpImageProcedure's… 2024-10-28 22:08:45 +01:00
script-fu-script.c ScriptFu: fix #12696 improper reffing of object proxies 2025-01-08 08:11:59 -05:00
script-fu-script.h extensions, libgimp, plug-ins: remove n_drawables arg from GimpImageProcedure's… 2024-10-28 22:08:45 +01:00
script-fu-scripts.c ScriptFu: move init scripts to separate directory /scripts/scriptfu-init 2024-10-25 13:56:36 +00:00
script-fu-scripts.h ScriptFu: add Scheme language function script-fu-register-regular 2024-09-27 14:35:50 +00:00
script-fu-types.h ScriptFu: add Scheme language function script-fu-register-regular 2024-09-27 14:35:50 +00:00
script-fu-utils.c
script-fu-utils.h
script-fu-version.c plug-ins: fix include. 2024-04-11 10:47:20 +02:00
script-fu-version.h Fix #10044 more natural binding of PDB return values 2024-03-09 07:21:50 -05:00
script-fu-widgets-custom.c ScriptFu: fix #12188 new-style dialog lacks slider widget 2024-10-18 14:35:17 -04:00
script-fu-widgets-custom.h 2.99 ScriptFu: add custom widgets to GimpProcedureDialog 2024-02-03 15:27:16 +00:00
script-fu.def ScriptFu: fix #10307 plugin call display not effective 2024-04-25 12:51:00 +00:00

About libscriptfu

libscriptfu is part of GIMP.
It is not generally useful except by GIMP.

The libscriptfu library is used by plugin executables,
and the PDB procedures they create,
all part of the "ScriptFu" machinery.

The libscriptfu library is not intended for third-party developers,
only for core GIMP developers.
Headers for libscriptfu might not be installed.

This directory contains three libraries: libscriptfu, tinyscheme, and ftx.
The tinyscheme library contains a TinyScheme interpreter.
The ftx library extends the TinyScheme interpreter,
adding file functions to the Scheme language.
The libscriptfu library contains both the tinyscheme and ftx libraries.
The libscriptfu library wraps the TinyScheme interpreter,
specializing it for GIMP.
The script-fu executable uses the libscriptfu library,
to interpret Scheme scripts that GIMP users refer to as "plug-ins."

These libraries depend on other libraries, e.g. math, libgimp, glib, etc.

Coupling between the executables and the libraries should be in one direction:
source for the inner libs should not include headers from the outer executables.
This lets you more easily update the inner libraries
(which originated elsewhere and might be maintained elsewhere),
and change the outer executables
(which are subject to change by GIMP developers.)

Example (which may change):
The script-fu executable is a plugin file that implements PDB procedures:
extension-script-fu, script-fu-console, script-fu-text-console, script-fu-eval,
and script-fu-server.
Each of those PDB procedures runs as a separate process.
Each of those processes uses libscriptfu.
The main PDB procedure is extension-script-fu, which is a long-lived process.
It is a PDB procedure of PDBProcedureType EXTENSION.
It interprets the Scheme scripts that user's call "plug-ins."

Rarely two of the PDB procedure processes run concurrently.
When they do, and libscriptfu is built as a shared library,
the read-only, code portion of the library is only loaded in memory once.