mirror of
https://github.com/bjc/prosody.git
synced 2025-04-03 05:07:42 +03:00
util.envload: Remove Lua 5.1 method
Part of #1600 Is this module even needed anymore?
This commit is contained in:
parent
dff4beae02
commit
bcc6efb2aa
1 changed files with 10 additions and 29 deletions
|
@ -6,38 +6,19 @@
|
||||||
--
|
--
|
||||||
-- luacheck: ignore 113/setfenv 113/loadstring
|
-- luacheck: ignore 113/setfenv 113/loadstring
|
||||||
|
|
||||||
local load, loadstring, setfenv = load, loadstring, setfenv;
|
local load = load;
|
||||||
local io_open = io.open;
|
local io_open = io.open;
|
||||||
local envload;
|
|
||||||
local envloadfile;
|
|
||||||
|
|
||||||
if setfenv then
|
local function envload(code, source, env)
|
||||||
function envload(code, source, env)
|
return load(code, source, nil, env);
|
||||||
local f, err = loadstring(code, source);
|
end
|
||||||
if f and env then setfenv(f, env); end
|
|
||||||
return f, err;
|
|
||||||
end
|
|
||||||
|
|
||||||
function envloadfile(file, env)
|
local function envloadfile(file, env)
|
||||||
local fh, err, errno = io_open(file);
|
local fh, err, errno = io_open(file);
|
||||||
if not fh then return fh, err, errno; end
|
if not fh then return fh, err, errno; end
|
||||||
local f, err = load(function () return fh:read(2048); end, "@"..file);
|
local f, err = load(fh:lines(2048), "@" .. file, nil, env);
|
||||||
fh:close();
|
fh:close();
|
||||||
if f and env then setfenv(f, env); end
|
return f, err;
|
||||||
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
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return { envload = envload, envloadfile = envloadfile };
|
return { envload = envload, envloadfile = envloadfile };
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue