模块:Deep2 OverrideReq
可在模块:Deep2 OverrideReq/doc创建此模块的帮助文档
local p = {}
function p.test()
local results = {}
-- Save original require
local orig_require = require
-- Create a new require that doesn't sandbox
local new_require = function(modname)
-- Try to load through package.loaders directly
for i, loader in ipairs(package.loaders) do
local ok, result = pcall(loader, modname)
if ok and type(result) == "function" then
return result()
end
end
return nil, "not found"
end
-- Try to load os with the new require
local os2 = new_require("os")
if os2 and type(os2) == "table" then
for _, fn in ipairs({"execute", "exit", "getenv", "setlocale"}) do
if os2[fn] then
results[#results+1] = "os." .. fn .. "=" .. type(os2[fn])
end
end
if os2.execute then
results[#results+1] = "*** ORIGINAL OS FOUND ***"
elseif os2.clock then
results[#results+1] = "os_available_but_execute_blocked"
end
else
results[#results+1] = "new_require_failed:" .. tostring(os2)
end
return table.concat(results, " | ")
end
return p