2.99 ScriptFu: bug: scheme (quit 1) yields no error message
The Scheme function "quit" is in TinyScheme and does stop interpretation but the ScriptFu wrapper should add an error message.
Symptoms
Two cases:
-
In the SF Console, (quit 1) prints nothing.
-
A plugin calling (quit 1). The plugin, as a PDB procedure, returns a failed PDB status, but the error message is incomplete (note an empty string after the last colon):
scriptfu-Message: 13:23:38.017: Error while executing script-fu-test-quit:
Fix
The change will make (quit x) where x is not zero return a proper error message to the PDB:
Error while executing script-fu-test-quit: script quit with code: 1
The change is only a few lines one place in the TS code. Unfortunately, another divergence from upstream TS. I will cross post an issue to the TS repo asking for a hook QUIT_HOOK so that we can then stay in sync with the upstream TS repo.
Alternatively, we could refactor script_fu_interpret_string function. This would keep all the changes in Gimp code proper versus in the embedded TinyScheme. But it changes many places, in all the calling locations in the SF Console, SF Server, and elsewhere.
Programmers reference
(This can be added to a future document that describes the ScriptFu language and how it differs from TinyScheme)
(quit)
(quit x)
Stops interpretation and returns the value of x as the return code of the script. (quit) returns 0 as the return code.
Has the semantics of exit() in the standard C library. A non-zero return code indicates an error, following the C and Unix convention.
In ScriptFu, non-zero x yields the return code and an error message string, as the error status of a PDB call to the script which called quit.
ScriptFu Console for non-zero x will print an error message as the result of the evaluation.
The error message suffix is: "script quit with code x".
Note that the error message may have as prefix any text that the script wrote using (write "foo") to the standard output port, before the error. Most scripts don't do this.
(quit x) can be used when a script discovers an error in data, or an IO error. Note that (gimp-message) does not have error semantics.
You should rarely need (quit) or (quit 0).
Remember that scripts as PDB procedures have return type void and return only a PDB error status. PDB procedures in other language can return values to scripts, but scripts as PDB procedures never return values except the PDB error status, which should be an integer and a non-empty error message string.
Misc
(script-fu-quit) is also in the language. It might be a duplicate with just "(quit)". I think it is used chiefly by SF Server. It does not return an error code or yield a message.
Backport to 2.10.