lua-users home
lua-l archive

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



On 26/03/2014 05:08, Thomas Jericke wrote:
On 03/26/2014 06:53 AM, Luiz Henrique de Figueiredo wrote:
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.

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.

But than you could also just write:

if _VERSION ~= "Lua 5.3" then
    error "This code needs Lua 5.3"
else
    load [[
Do()
Some()
Stuff()
]]

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
etc
etc
]],"filename.lua")
if not f then error(e) else stuff() end