Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Pass Perl functions to Tcl interpreter
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  5 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Kevin Walzer  
View profile  
 More options Aug 19 2012, 1:19 pm
Newsgroups: perl.tcltk
From: k...@codebykevin.com (Kevin Walzer)
Date: Sun, 19 Aug 2012 13:19:41 -0400
Local: Sun, Aug 19 2012 1:19 pm
Subject: Pass Perl functions to Tcl interpreter
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#RAT...)
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


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Alexander Nusov  
View profile  
 More options Aug 19 2012, 5:25 pm
Newsgroups: perl.tcltk
From: alexander.nu...@gmail.com (Alexander Nusov)
Date: Mon, 20 Aug 2012 01:25:15 +0400
Local: Sun, Aug 19 2012 5:25 pm
Subject: Re: Pass Perl functions to Tcl interpreter
Hello Kevin.

You can run perl code from tcl interpreter using (works for Tkx)
::perl::Eval {
   # perl code  

}

for example,
sub do_something {
   print "Hello\n";

}

Tkx::eval(<<EOT

# … TCL code
# ...
proc invoke_perl_code {} {
  ::perl::Eval {
     main::do_something();
  }

}

invoke_perl_code

EOT
);

--  
Best regards,
Alexander Nusov


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jeff Hobbs  
View profile  
 More options Aug 19 2012, 5:38 pm
Newsgroups: perl.tcltk
From: je...@activestate.com (Jeff Hobbs)
Date: Sun, 19 Aug 2012 14:38:00 -0700
Subject: Re: Pass Perl functions to Tcl interpreter
Hi Kevin,

The binding for Tkx is much more efficient than Tkinter, and does allow for 2 way communication and command binding in the interface.

Alexander noted you have ::perl::Eval in Tcl, but there are more ways to bind the 2 pieces together.  I would recommend looking at the code for ppm in ActivePerl, which uses Tkx in various elaborate ways (blending Tcl and Perl in interesting ways), for lots of good code examples.  See
  /usr/local/ActivePerl-<ver>/bin/ppm
  /usr/local/ActivePerl-<ver>/lib/ActivePerl/PPM/*

Note that ActivePerl uses Tkx via tkkits (baseballs with extended functionality).  These can be extended (see archives of this list), but you can use external packages as needed.

Jeff

On 2012-08-19, at 10:19 AM, Kevin Walzer wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Kevin Walzer  
View profile  
 More options Aug 20 2012, 10:22 am
Newsgroups: perl.tcltk
From: k...@codebykevin.com (Kevin Walzer)
Date: Mon, 20 Aug 2012 10:22:14 -0400
Local: Mon, Aug 20 2012 10:22 am
Subject: Re: Pass Perl functions to Tcl interpreter
On 8/19/12 5:38 PM, Jeff Hobbs wrote:

> Hi Kevin,

> The binding for Tkx is much more efficient than Tkinter, and does allow for 2 way communication and command binding in the interface.

> Alexander noted you have ::perl::Eval in Tcl, but there are more ways to bind the 2 pieces together.  I would recommend looking at the code for ppm in ActivePerl, which uses Tkx in various elaborate ways (blending Tcl and Perl in interesting ways), for lots of good code examples.  See
>    /usr/local/ActivePerl-<ver>/bin/ppm
>    /usr/local/ActivePerl-<ver>/lib/ActivePerl/PPM/*

> Note that ActivePerl uses Tkx via tkkits (baseballs with extended functionality).  These can be extended (see archives of this list), but you can use external packages as needed.

> Jeff

Jeff,

Thanks to you and Alexander for this advice: it appears that I can
safely integrate Tcl's AppleEvent package with Tkx given the mechanisms
you describe. Awesome.

Thanks,
Kevin

--
Kevin Walzer
Code by Kevin
http://www.codebykevin.com


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Eric Windisch  
View profile  
 More options Aug 20 2012, 10:41 am
Newsgroups: perl.tcltk
From: e...@windisch.us (Eric Windisch)
Date: Mon, 20 Aug 2012 10:41:31 -0400
Local: Mon, Aug 20 2012 10:41 am
Subject: Re: Pass Perl functions to Tcl interpreter

On Sunday, August 19, 2012 at 13:19 PM, Kevin Walzer wrote:
> 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.

I've used CreateCommand in the past:

$name="new_cmd_name_in_tcl";$tcl->CreateCommand($name, sub {

> my $clientdata=shift; # this is set to "a_string_here"
> my $interp=shift;
> my $argc=shift;
> # @_ will contain argv
> call_some_perl_sub(@_);
}, "a_string_here");

You can use the $argc and $clientdata strings in interesting ways...

--
Eric Windisch


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »