zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <pws@ibmth.df.unipi.it>
To: zsh-workers@sunsite.auc.dk, Jeff Solomon <jsolomon@stanford.edu>
Subject: Re: Zsh and Perl?
Date: Thu, 05 Aug 1999 10:31:41 +0200	[thread overview]
Message-ID: <9908050831.AA28113@ibmth.df.unipi.it> (raw)
In-Reply-To: "Jeff Solomon"'s message of "Wed, 04 Aug 1999 11:13:27 DFT." <14248.30740.258799.3140@mrclean.Stanford.EDU>

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 <pws@ibmth.df.unipi.it>       Tel: +39 050 844536
WWW:  http://www.ifh.de/~pws/
Dipartimento di Fisica, Via Buonarroti 2, 56127 Pisa, Italy


  parent reply	other threads:[~1999-08-05  9:03 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-08-04 18:13 Jeff Solomon
1999-08-04 22:02 ` Bruce Stephens
1999-08-05  5:39 ` Bart Schaefer
1999-08-05  8:31 ` Peter Stephenson [this message]
1999-08-23 11:30 Mike Fletcher

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9908050831.AA28113@ibmth.df.unipi.it \
    --to=pws@ibmth.df.unipi.it \
    --cc=jsolomon@stanford.edu \
    --cc=zsh-workers@sunsite.auc.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).