2 -- Copyright (C) 2008-2011 Florian Zeitz
4 -- This project is MIT/X11 licensed. Please see the
5 -- COPYING file in the source package for more information.
7 -- luacheck: ignore 113/setfenv 113/loadstring
9 local load
, loadstring
, setfenv
= load
, loadstring
, setfenv
;
10 local io_open
= io
.open
;
15 function envload(code
, source
, env
)
16 local f
, err
= loadstring(code
, source
);
17 if f
and env
then setfenv(f
, env
); end
21 function envloadfile(file
, env
)
22 local fh
, err
, errno
= io_open(file
);
23 if not fh
then return fh
, err
, errno
; end
24 local f
, err
= load(function () return fh
:read(2048); end, "@"..file
);
26 if f
and env
then setfenv(f
, env
); end
30 function envload(code
, source
, env
)
31 return load(code
, source
, nil, env
);
34 function envloadfile(file
, env
)
35 local fh
, err
, errno
= io_open(file
);
36 if not fh
then return fh
, err
, errno
; end
37 local f
, err
= load(fh
:lines(2048), "@"..file
, nil, env
);
43 return { envload
= envload
, envloadfile
= envloadfile
};