Return Scheme #f and #t for a call to a PDB proc declared returning GBoolean
In a script, a call to a PDB procedure declared to return GType GBoolean, yields an integer (aka numeric) to Scheme. However, 0 is truthy, not falsy, in Scheme.
In the ScriptFu console:
(if (gimp-item-is-layer-mask 1) (gimp-message "true") (gimp-message "false"))
yields "true" even when item with ID 1 is not a layer mask.
To show that 0 is not falsy in Scheme:
(eqv? 0 #f)
This is not pertinent to 2.10 since no PDB procedure was or could be declared to return a boolean type (GIMP_PDB_BOOLEAN is not defined.)
2.99 ScriptFu diverged only about two years ago. There are scripts in the GIMP repo that call PDB procedures now declared to return GBoolean. They use constructs from v2, e.g. :
(if (= FALSE (car (gimp-selection-is-empty theImage)))
Which works because in scheme_wrapper.c at line 101, ScriptFu defines into the Scheme environment symbols TRUE and FALSE, having integer values the C notions of true and false (1 and 0.)
/* Useful misc stuff */
{ "TRUE", TRUE },
{ "FALSE", FALSE },
So this is not actually a bug, only an enhancement. The enhancement would let scripts be less wordy and more Schemey. There would be no FALSE and TRUE symbols defined, only the standard Scheme symbols/objects #f and #t.
To implement the enhancement:
- remove the lines above,
- change a few lines changed near scheme-wrapper.c line 1380, to yield sc->F or sc->T instead of a numeric.
- change the scripts in the repo using constructs like above
The enhancement would break many existing third party scripts.
This enhancement may be controversial. If we are going to implement it, now is the time, so that ScriptFu has a clean start at 3.0.