fix(wget): 确保常用模块加载并改进代码执行方式

添加对常用模块的检查加载,并使用pcall安全执行下载的代码以避免直接崩溃
This commit is contained in:
2025-08-31 20:51:29 +08:00
parent 1160a24a51
commit 311b49a3e5

View File

@@ -31,11 +31,19 @@ end
if args[1] == "run" then
local data = get(args[2])
-- 确保fs模块已加载
if not _G.fs then
_G.fs = require("fs")
-- 确保常用模块已加载
if not _G.fs then _G.fs = require("fs") end
if not _G.term then _G.term = require("term") end
if not _G.colors then _G.colors = require("colors") end
if not _G.textutils then _G.textutils = require("textutils") end
if not _G.shell then _G.shell = require("shell") end
-- 执行下载的代码
local func, err = load(data, "=<wget-run>", "t", _G)
if not func then
error("Failed to load downloaded code: " .. err, 0)
end
assert(load(data, "=<wget-run>", "t", _G))()
assert(pcall(func))
else
local filename = args[2] or (args[1]:match("[^/]+$")) or
error("could not determine file name", 0)