From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 21749 invoked from network); 5 Aug 1999 09:03:06 -0000 Received: from sunsite.auc.dk (130.225.51.30) by ns1.primenet.com.au with SMTP; 5 Aug 1999 09:03:06 -0000 Received: (qmail 4820 invoked by alias); 5 Aug 1999 09:02:50 -0000 Mailing-List: contact zsh-workers-help@sunsite.auc.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 7366 Received: (qmail 4813 invoked from network); 5 Aug 1999 09:02:49 -0000 Message-Id: <9908050831.AA28113@ibmth.df.unipi.it> To: zsh-workers@sunsite.auc.dk, Jeff Solomon Subject: Re: Zsh and Perl? In-Reply-To: "Jeff Solomon"'s message of "Wed, 04 Aug 1999 11:13:27 DFT." <14248.30740.258799.3140@mrclean.Stanford.EDU> Date: Thu, 05 Aug 1999 10:31:41 +0200 From: Peter Stephenson Jeff Solomon wrote: > I'm very sorry if this question seems naive but I've dug a little > through the zsh source code and it seems appropriate. It's a perfectly reasonable question, and one that really demands a more practical solution than it's got up to now (i.e. actually writing). > Embed perl into zsh: > > Looking at the source, this looks like the most straightforward > thing to do. It seems easy to add a 'perl_eval' command that would > evaluate a snippet of perl in a persistent interpreter. This certainly seems like the way to go, and it should be easy: just follow the `perlembed' instructions, but put the result in a zsh module (look at a simple one with its own builtin like `stat' for guidance). > But I > would want to add command into the zsh enviroment from perl so I > can type: > > my_command my_arg1 my_arg2 > > instead of > > perl_eval 'my_command my_arg1 my_arg2' > > which means you'd have to add support for calling back into zsh > from perl. You mean that `my_command' is a perl command, but is handled by the zsh command line interface, and calls a perl subroutine? That should be just as easy, I don't see you need to call back into zsh --- unless the problem is simply adding the perl command when a perl module is loaded. The zsh code for doing this is easy, just use addbuiltin(). Then you need to make some zsh interface code visible from the perl interpreter you've just built, and that I can't visualize without some hands-on experience. Doing it this way round usually means creating a library with some xs code, which would be the wrong way round for embedding perl in zsh. A quick glance at the perlembed manual page doesn't seem to help much. You'd get more help on this angle from the perl people. > Embed zsh into perl: Once you've solved the previous problem, you can actually sort of do this too, by the same method. Just make some code available which calls something looking like bin_eval() (in builtin.c); then you have the effect of a system() command without a fork. If you want the full effect of perl's `system', where a call with more than one argument is treated specially, you have to work harder. Any suitably general purpose module for doing this could be part of the main distribution. Ideally, in that case (and again, there may be other issues), you might want ways of getting/setting perl variables via zsh variables and that sort of thing. The special variable code may well now be powerful enough to handle this (make access go through perl_get_sv() etc.), but a look at Src/Modules/parameter.c will show it's still pretty hairy (though that's complicated by the fact it's intercepting the associative array interface, which means an extra level of lookup). -- Peter Stephenson Tel: +39 050 844536 WWW: http://www.ifh.de/~pws/ Dipartimento di Fisica, Via Buonarroti 2, 56127 Pisa, Italy