Object-Oriented Versus Procedural Scripting
If you are familiar with the structure of Gimp plug-ins written in C, you will immediately notice a few details of the previous example that differ between Perl and C. Because Gimp-Perl is a scripting extension that acts as a high-level interface to libgimp (the Gimp API), you do not necessarily have to use the clumsy PDB-style calling syntax that you must use in C.
All libgimp functions and additional plug-ins are registered in
the Procedural Database. The entries in the PDB serve to document the
Gimp API; you can use the PDB Browser (found under the Xtns menu) to
search the API. As shown in Figure 5-2, the browser displays the
function interfaces using C syntax. For example, if you want to copy a
layer using the function gimp_layer_copy(
), you would look up the function in the browser and write
the function call (in C) as:
ret_vals = gimp_run_procedure("gimp_layer_copy",
&nret_vals,
PARAM_LAYER, layerID,
PARAM_INT32, TRUE,
PARAM_END);
In Perl you can call the function more simply:
$new_layer = gimp_layer_copy($layer, 1);
Note that the style shown above can be used only if you have
imported the Gimp API function names with the :auto tag. Otherwise, you would have to
specify the package name:
$new_layer = Gimp::gimp_layer_copy($layer, 1);
You can get away with sticking to the simple procedural-style calling ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access