zsh-workers
 help / color / mirror / code / Atom feed
* Re: Zsh and Perl?
@ 1999-08-23 11:30 Mike Fletcher
  0 siblings, 0 replies; 5+ messages in thread
From: Mike Fletcher @ 1999-08-23 11:30 UTC (permalink / raw)
  To: zsh-workers


        I've already got a start at a perl interpreter embeded into
zsh as a loadable module.  It's still *really* rough, but so far:

        *) you can do the equivalent of 'use Module' from zsh to load
           perl modules into the interpreter

        *) you can define builtins as perl subroutines 

        *) there's a minimal wrapper for accessing zsh parameters from
           perl code


        If there's any interest, mail me and I'll throw what I've got
up on the web.

        Also, please Cc any follow-ups to me; I'm having problems
getting subscribed to zsh-workers for some reason, which is why I
hadn't spoken up the first time this was mentioned.

-- 
Fletch                | "If you find my answers frightening,       __`'/|
fletch@phydeaux.org   |  Vincent, you should cease askin'          \ o.O'
678 443-6239(w)       |  scary questions." -- Jules                =(___)=
                      |                                               U


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Zsh and Perl?
  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
  2 siblings, 0 replies; 5+ messages in thread
From: Peter Stephenson @ 1999-08-05  8:31 UTC (permalink / raw)
  To: zsh-workers, Jeff Solomon

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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Zsh and Perl?
  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
  2 siblings, 0 replies; 5+ messages in thread
From: Bart Schaefer @ 1999-08-05  5:39 UTC (permalink / raw)
  To: Jeff Solomon, zsh-workers

On Aug 4, 11:13am, Jeff Solomon wrote:
} Subject: Zsh and Perl?
}
} I think a common task that many people are faced with is writing
} little debugging tools. Frequently, they may write such a tool in a
} language like Perl because it's so time efficient.

You may very well be correct, but I'd like an example of such a tool if
you can share one.  I wouldn't have referred to any of the perl tools I
write as "debugging" tools, but perhaps you're speaking as an admin who
has to debug network connections or protocols, or the like.

I say this because ...

} So I'm asking the zsh developers about the best way to solve this
} problem. Basically I want to [...]

... you seem to have already made up your mind about the best way to solve
the problem, and I want to be convinced that you're right.  Marrying perl
to zsh isn't going to help people who write tools in awk or tcl or python.

For example, have you considered running the debugging tool as a coproc?

Nevertheless, to answer your specific questions ...

} 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. But I
}     would want to add command into the zsh enviroment from perl [...]

Zsh 3.1.6 modules are the thing for this.  For one thing, you can load
and unload them dynamically; so you don't have to bloat zsh permanently
with a perl interpreter, and you can force the interpreter to shut down
if necessary -- and with a lot of OOPerl programs, that's required to get
all the object cleanup to happen.

For another thing, as of 3.1.6 loadable modules can export zsh parameters,
so you can theoretically make the perl scalar namespace visible to zsh.
You might even be able to make (copies of) perl arrays visible, and bits
of perl hashes, though zsh doesn't have nested arrays/hashes.

Finally, of course, zsh modules were originally designed to supply new
builtin commands, and you can add as many as you like from each module.

} Embed zsh into perl:
} 
}     zsh is turned into a loadable perl module and I write a script
}     directly using zsh.

That would be a major engineering effort.  Perl has already gone through
the necessary transformations to become a linkable interpreter "library"; 
zsh has not, and I suspect it would be an ugly task to do so.

} Has anyone done this yet?

It's been mentioned a number of times, but nobody has ever been motivated
enough to go through with it.

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Zsh and Perl?
  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
  2 siblings, 0 replies; 5+ messages in thread
From: Bruce Stephens @ 1999-08-04 22:02 UTC (permalink / raw)
  To: Jeff Solomon; +Cc: zsh-workers

Jeff Solomon <jsolomon@stanford.edu> writes:

[...]

> So I'm asking the zsh developers about the best way to solve this
> problem. Basically I want to either embed perl into zsh or embed zsh
> into perl, but the key is that my perl commands have to share state
> from one instance of a perl interpreter.

Why do you need Perl?  What do you need to do that can't be done in
zsh?  (I'm not doubting that there are things that Perl can do that
zsh can't, but perhaps the things you want to be able to do would be
valuable and sensible to add to zsh.)

> 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. 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.

Yes, this sort of thing has been proposed before.  I'm not sure
whether there was ever actual code, but I don't think there's any
serious barrier to having a Perl module, dynamically loadable into
zsh.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Zsh and Perl?
@ 1999-08-04 18:13 Jeff Solomon
  1999-08-04 22:02 ` Bruce Stephens
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Jeff Solomon @ 1999-08-04 18:13 UTC (permalink / raw)
  To: zsh-workers, pws


Hi,

I'm very sorry if this question seems naive but I've dug a little
through the zsh source code and it seems appropriate.

I think a common task that many people are faced with is writing
little debugging tools. Frequently, they may write such a tool in a
language like Perl because it's so time efficient. Then they realize
that they have no interface for their tool so they either write their
own or they have none at all or mostly have something just like this:

    while( get_input_line_from_terminal_driver ) {
      process_input_line
    }

This makes the interface really, really bad, but the tool writer wants 
to worry about whatever they are debugging (or whatever) and not the
interface.

I've been doing a few of these tools for our research group and I've
gotten pretty good at using libraries like GNU Readline to spruce up
my interfaces, but I find myself constantly trying to emulate what shells
like Zsh already do and do very well.

I've looked at the source for tcsh, bash and now zsh and zsh *by far*
looks the best written and best suited for this task because it seems
so modular.

So I'm asking the zsh developers about the best way to solve this
problem. Basically I want to either embed perl into zsh or embed zsh
into perl, but the key is that my perl commands have to share state
from one instance of a perl interpreter.

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. 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.

Embed zsh into perl:

    zsh is turned into a loadable perl module and I write a script
    directly using zsh. It might look something like this:

    use Shell::Zsh;

    my $zsh = Shell::Zsh->new;

    $zsh->register_command_callback(\&my_callback);

    $zsh->other_customizations.... (add commands for completion, etc)

    $zsh->mainloop;

    sub my_callback {
       process command
    }
    
Anyway, I've gone on long enough. I'm just looking for feedback on
this general idea. Has anyone done this yet? (searching through the
source for 'perl' doesn't find much, and searching the website for
'perl' never returns). Any ideas on which option would be easier to
implement/use?

Any thoughts would be appreciated.

Jeff


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~1999-08-25 11:00 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-08-23 11:30 Zsh and Perl? Mike Fletcher
  -- strict thread matches above, loose matches on Subject: below --
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

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).