# HG changeset patch # User Kim Alvefur # Date 1657023512 -7200 # Node ID d1aacc6a81ac035c4fcf2b3cfccf4e893dfb3abf # Parent 1f6f05a98fcd188748b80391dd24608b890963b0 util.envload: Remove Lua 5.1 method Part of #1600 Is this module even needed anymore? diff -r 1f6f05a98fcd -r d1aacc6a81ac util/envload.lua --- a/util/envload.lua Fri Jul 01 21:21:21 2022 +0200 +++ b/util/envload.lua Tue Jul 05 14:18:32 2022 +0200 @@ -6,38 +6,19 @@ -- -- luacheck: ignore 113/setfenv 113/loadstring -local load, loadstring, setfenv = load, loadstring, setfenv; +local load = load; local io_open = io.open; -local envload; -local envloadfile; -if setfenv then - function envload(code, source, env) - local f, err = loadstring(code, source); - if f and env then setfenv(f, env); end - return f, err; - end +local function envload(code, source, env) + return load(code, source, nil, env); +end - function envloadfile(file, env) - local fh, err, errno = io_open(file); - if not fh then return fh, err, errno; end - local f, err = load(function () return fh:read(2048); end, "@"..file); - fh:close(); - if f and env then setfenv(f, env); end - return f, err; - end -else - function envload(code, source, env) - return load(code, source, nil, env); - end - - function envloadfile(file, env) - local fh, err, errno = io_open(file); - if not fh then return fh, err, errno; end - local f, err = load(fh:lines(2048), "@"..file, nil, env); - fh:close(); - return f, err; - end +local function envloadfile(file, env) + local fh, err, errno = io_open(file); + if not fh then return fh, err, errno; end + local f, err = load(fh:lines(2048), "@" .. file, nil, env); + fh:close(); + return f, err; end return { envload = envload, envloadfile = envloadfile };