- Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathrequire.lua
More file actions
Latest commit
26 lines (26 loc) · 1.02 KB
/
Copy pathrequire.lua
File metadata and controls
26 lines (26 loc) · 1.02 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
-- pure-lua require since the luajit one has C-call boundary yield problems (maybe? 10yo bug? https://github.com/openresty/lua-nginx-module/issues/376#issuecomment-46104284 )
returnfunction(env)
env=envor_G
--local oldrequire = env.require
localpackage=env.package
env.require=function(modname)
localmod=package.loaded[modname]
ifmod~=nilthenreturnmodend
localerrs= {"module '"..tostring(modname).."' not found:"}
localsearchers=assert(package.searchersorpackage.loaders, "couldn't find searchers")
for_,searchinipairs(searchers) do
localresult=search(modname)
localresulttype=type(result)
ifresulttype=='function' then
localmod=result() ortrue
package.loaded[modname] =mod
returnmod
elseifresulttype=='string' orresulttype=='nil' then
table.insert(errs, result) -- if I get a nil, should I convert it into an error?
else
error("package.searchers result got an unknown type: "..resulttype)
end
end
error(table.concat(errs))
end
end