[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: #! /bin/lua (was Re: ~= vs. !=)
- From: Rob Kendrick <lua-l@...>
- Date: Thu, 27 Nov 2003 15:42:17 +0000
On Thu, 2003-11-27 at 15:24, Daniel Silverstone wrote:
> On Thu, 2003-11-27 at 15:10, Peter Hill wrote:
> > > the 'shebang' as it is often referred to indicates to the kernel (or
> > > shell, or whatever feels like parsing it) what program to run (and what
> > > args to give it) to get it to parse the program in question...
> > Ie, it denotes that the rest of the file is an 'executable' suitable for
> > handling by the program mentioned in the 'shebang'.
> It denotes that the entire file (including the shebang) is for the
> program mentioned.
Which is typically ignored because it's a comment. Not because of the
design of the language, but the design of the shebang system.
> Also, pre-pending a
> shebang to a lump of binary goo (while completely 'correct' from the
> point of view of unix) somewhat goes against the grain that the shebang
> is meant for human-editable scripting languages rather than 'compiled'
Why? I think of it as a system for specifying how to deal with a file
with the x bit set that the kernel doesn't know how to deal with. I
think the only reason it is plain text itself is that it's *typically*
used for plain-text stuff. From the user's point of view, doing:
does exactly the same as
The contents, or the formatting of what is in the file really doesn't
matter to them.
> > Rob Kendrick:
> > > It already does rely on system knowledge. (The ignoring of #! lines in
> > > text lumps.)
> > You said it all!
> > The core of Lua should not rely on any operating system stuff, and Shebangs
> > are just that! Not all Operating Systems use them and unless Lua is compiled
> > for such a system it *should* have such OS-specific code commented out!
> I think here is where you hit the nail on the head. The shebang *is* for
> UNIX and unixlike operating systems and to an extent, really shouldn't
> be included if you compile your Lua binary to run on Windows (excepting
> of course the facilities which Cygwin offers you).
> My essential gripe with your posting before (which both you and Rob
> appeared to miss) was simply that on systems where you would expect a
> shebang to work, it *IS* up to the interpreter (lua in this case) to
> handle the shebang, since the OS will simply trigger on it and launch
> the right interpreter with some commandline arguments. There is no
> institutionalised stripping of the shebang before the interpreter gets
> its hands on the file.
I never suggested that the shebang line was stripped by the OS. Infact,
I'm advocating that lua universally ignore the shebang line, rather than
just on textual lumps.
What would make me happy is that lua_load function deals with this,
rather than the lexer. That way it works perfectly with both. And if
it's up to the interpreter to ignore it, why doesn't it if it's a
> Having the type information and semantics for loading the right
> interpreter "out of band" seems to be your argument, and to that extent,
> using the linux binfmt_misc associations, or the windows extension
> associations (or whatever your particular OS chooses to provide) is the
> more pleasant way of going about it.
Except, as I said before, is actually less common, less portable, and
less easily done by users.
> Your only issue then, is what if I want to write a lua program which
> uses *my* lua interpreter which I compiled and put somewhere else on the
> system? If the decision is hidden away from the user in some system
> defined way, how can I tell the OS to use my interpreter instead?
Same argument goes for shell scripts and perl scripts, though. You just
do /path/to/my/interpreter filename, instead :)
> Anyway, an interesting set of comments by all three of us I think, and
> perhaps the Lua guys will consider making the #! skipping part of the
> ZIO layer rather than the parser (if it isn't already) and as such make
> it possible for shebangs to prefix compiled chunks; and subsequent to
> that, make it possible to compile it out (perhaps via a -DNOSHEBANG in
> the CFLAGS) if you don't want such processing in your system.
Lua 5 already knows if it's running on a POSIX system (as it enables
popen() support by default for them). Moving the #! ignoring stuff to
lua_load or similar from the lexer, and wrapping it in some #if would be
trivial. (I've just tried it here, as a proof of concept, and it works
Rob Kendrick, Pepperfish Ltd. +44 (0)845 226 4146 www.pepperfish.net
PGP signed or encrypted mail welcome Key ID: 3651D17A