Stop using setfenv for compatibility with modern Luas.

This commit is contained in:
David Given 2022-07-13 20:27:49 +02:00
parent 62ba0833bd
commit bbae0ba02c

View file

@ -345,11 +345,10 @@ local function templateexpand(list, vars)
o[#o+1] = s:gsub("%%%b{}", o[#o+1] = s:gsub("%%%b{}",
function(expr) function(expr)
expr = expr:sub(3, -2) expr = expr:sub(3, -2)
local chunk, e = loadstring("return ("..expr..")", expr) local chunk, e = load("return ("..expr..")", expr, nil, vars)
if e then if e then
error(string.format("error evaluating expression: %s", e)) error(string.format("error evaluating expression: %s", e))
end end
setfenv(chunk, vars)
local value = chunk() local value = chunk()
if (value == nil) then if (value == nil) then
error(string.format("template expression '%s' expands to nil (probably an undefined variable)", expr)) error(string.format("template expression '%s' expands to nil (probably an undefined variable)", expr))
@ -381,10 +380,7 @@ local function loadbuildfile(filename)
local thisglobals = {} local thisglobals = {}
thisglobals._G = thisglobals thisglobals._G = thisglobals
setmetatable(thisglobals, {__index = globals}) setmetatable(thisglobals, {__index = globals})
chunk, e = loadstring(data, "@"..filename) chunk, e = load(data, filename, nil, thisglobals)
if not e then
setfenv(chunk, thisglobals)
end
end end
end end
if e then if e then