Hello all,
I'm learning Perl and Tkx and am wondering if it is possible to pass
Perl functions to the Tcl interpreter in a manner similar to Python's
"register" method in the Tkinter module. In Python, you can call
register("mypythonfunction"), which is then passed to the Tcl
interpreter as though it were a Tcl procedure. This functionality is
useful when interacting wtih the Tcl interpreter at a low level.
Let me explain my interest in this issue. I'm working on Mac OS X and am
trying to build a Perl/Tkx application that supports responding to
AppleEvents, i.e. you can script the Perl-based application via
AppleScript just like you can script Safari, iTunes, Photoshop, and
other apps. Perl, though, lacks up-to-date methods for integrating with
AppleScript; its current methods, such as
http://search.cpan.org/~cnandor/Mac-AppleEvents-Simple-1.18/Simple.pm,
are based on deprecated functions that don't work in a 64-bit context,
which is essential.
I've investigated alternative approaches for adding such functionality,
such as creating a SWIG-based extension, but SWIG doesn't allow
callbacks into the Perl interpreter. Another approach I've researched is
using SWIG to call out to a helper Perl application that would then call
the main Perl application via some sort of RPC mechanism, but all the
RPC mechanisms I've tried (numerous links at
http://search.cpan.org/~powerman/JSON-RPC2-0.1.1/lib/JSON/RPC2.pm#RATIONALE)
are all half-baked in some way. (If someone can point me to an RPC
module they've had success with, I'd be grateful. Ruby's "druby" module
is elegant and simple, but its lack of desktop app deployment tools for
the Mac make Ruby unsuitable.)
So the approach I'd like to try is installing AppleEvent handlers via
Tcl's TclAE package: this is a powerful package that can install the
appropriate AppleEvents and then execute event handlers in the Tcl
interpreter. Integrating this with Perl would, ideally, involve some
sort of mechanism where I can "register" a Perl function that is passed
to the Tcl interpreter and executed as if it were Tcl code.
Advice is appreciated.
Thanks,
Kevin
--
Kevin Walzer
Code by Kevin
http://www.codebykevin.com