[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Could we have elegant version requirement from 5.3 on?
- From: Sean Conner <sean@...>
- Date: Wed, 26 Mar 2014 03:57:28 -0400
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
 and loading it with luaL_loadbuffer()  and received a parsing error
> 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.
> #! /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 ...
 #!/usr/bin/env lua
 Originally, I was precompiling the Lua code, then embedding it:
On a lark, I decided to try compressing the actual text instead of
the compiled version, and found it compressed much better.
 It's clear that lua and luac toss the first line if it starts with a