lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


It was thus said that the Great Dirk Laurie once stated:
> There seems to be no way of making Lua code say politely:
> "This program requires Lua 5.3" when running under Lua 5.2.
> Instead, one gets a nasty message like
> 
> ./myprog.lua:28: unexpected symbol near '&'
> 
> as soon as it hits a bitwise operator.
> 
> But maybe it is not late for next time round.  We are already
> ignoring one leading `#` line. 

  I don't think ignoring the leading '#' is done in the parser.  I tried
embedding the source code to some Lua code that starts with a shebang line
[1] and loading it with luaL_loadbuffer() [2] and received a parsing error
[3].

> We could equally well ignore
> all leading `#` lines and tag some of them as expressions to be
> asserted _before_ proceeding to lexical analysis of the file.
> This would allow elegant version control and more.
> 
> E.g.
> 
> #! /usr/bin/env lua
> #@ _VERSION >= 6.0
> #@ bit32
> 
> When Lua 5.3 runs this program, or Lua 6.0 runs it without
> having preloaded a bit32 library, the rest of the file would not
> even be looked at.

  I thought something like:

#!/usr/bin/env lua -e "if _VERSION ~= 'Lua 5.3' then print('bad lua') return end" - 

would work, but apparently not ... 

  -spc 

[1]	#!/usr/bin/env lua

[2]	Originally, I was precompiling the Lua code, then embedding it:

	http://boston.conman.org/2013/03/22.1
	http://boston.conman.org/2013/03/23.1

	On a lark, I decided to try compressing the actual text instead of
	the compiled version, and found it compressed much better.

[3]	It's clear that lua and luac toss the first line if it starts with a
	shebang [1].