[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Could we have elegant version requirement from 5.3 on?
- From: "Thiago L." <fakedme@...>
- Date: Wed, 26 Mar 2014 10:54:29 -0300
On 26/03/2014 05:08, Thomas Jericke wrote:
On 03/26/2014 06:53 AM, Luiz Henrique de Figueiredo wrote:
Wouldn't that mean you would have to replace the loader in the code
being loaded. The only solution I see is to have a wrapper code around
the actual code.
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 is easily done with a custom reader function for load.
But than you could also just write:
if _VERSION ~= "Lua 5.3" then
error "This code needs Lua 5.3"
But I think that has some disadvantages too. Like losing the file name
and lines in the debug info. It seems to me that something like a
static assert would be the right thing here.
Something like this should work: (as you can see, the first line of the
module is on the first line of the file, etc)
if _VERSION ~= "Lua 5.3" then error "whatever" end local f,e = load([[
FIRST LINE OF CODE HERE
if not f then error(e) else stuff() end