lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Luiz Henrique de Figueiredo wrote:
Another nice project is to bind Lua to GIMP, but I don't know how large the
job would be. Perhaps Adam Moss (adam at gimp.org) knows?

That's a great idea that inexplicably hadn't really crossed
my mind before.  I could even see Lua having some nice advantages
over the two officially-supported languages for GIMP scripting
(SIOD-scheme and PERL).  My leisure-hacking time is practically
nonexistant so I doubt that I would implement it myself though.

It should be fairly easy to implement -- GIMP has its own API
(the 'procedural database', or 'pdb') intended to make this sort of
thing fairly painless.  In the current GIMP CVS HEAD, check out
tools/pdbgen for the tools designed to generate static bindings
for various languages (with a little coaxing); additionally, and
probably more usefully for Lua binding, the pdb can by dynamically
queried for the available interfaces (supplied by either the core
or registered plugins and scripts) and their call signatures.
Only simple types are generally passed over pdb interfaces, so
marshalling should be quite easy.

A module written as a GIMP 'extension' (which is basically
a persistant plugin) would handle the calling through the pdb's
generalized invocation interface (not the specific C interface,
since there's not real point AFAIK), and the marshalling of
arguments and returned values.  At the Lua side, I imagine
that all calls to objects in a 'gimp' table would be caught by
a metamethod which would substitute a general-pdb-invoking function
with the offending index string as a closure so that when this
function is called it can send the function name and parameters
over to the C-side pdb marshaller.

That's probably about a day or two's work, to get things basically
working.  The interface offered by the pdb is actually fairly
high-level already, so no gimp-specific utilities on the Lua side
are strictly necessary, though they would certainly be useful as
a bonus.

This method would allow users to write their own GIMP plug-ins
in Lua (plug-ins can do a lot).  That's a different thing to
being able to access a running GIMP's functionality from an
arbitrary and independant Lua script, though.  I'm not sure how
much more work that sort of thing would be; I haven't looked into
how PERL and CGI-ready GIMP scripting handle this.

Regards,
--Adam
--
Adam D. Moss   . ,,^^   adam@gimp.org   http://www.foxbox.org/   co:3
"Responsible parents don't raise kids in West Virginia."