-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.lua
More file actions
34 lines (33 loc) · 1.26 KB
/
init.lua
File metadata and controls
34 lines (33 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
local setfenv, unpack, pcall, assert, loadfile = setfenv, unpack, pcall, assert, loadfile;
local package, os, string = package, os, string;
local loaded, preload, path, getenv, gmatch = package.loaded, package.preload, package.path, os.getenv, string.gmatch;
local env = getfenv();
local tab = string.char(9);
local require = function(dir)
if (loaded[dir] ~= nil) then
return loaded[dir];
end;
local paths = LUA_PATH or getenv('LUA_PATH') or path;
local loader = preload[dir];
if (loader ~= nil) then
local closure = {setfenv(loader, env)(dir)}
loaded[dir] = unpack(closure);
return unpack(closure);
end;
local check_traceback = tab.."no field package.preload['"..dir.."']";
for path in gmatch(paths, '[^;]+') do
local true_path = path:gsub('?', dir);
local ran, result = pcall(function()
return assert(loadfile(true_path));
end);
if (ran == true) then
local closure = {setfenv(result, env)(dir)}
loaded[dir] = unpack(closure);
return unpack(closure);
end;
check_traceback = check_traceback..'\n'..tab.."no file '"..true_path.."'";
end;
error("module '"..dir.."' not found:\n"..check_traceback);
end;
env.require = require;
return require;