mirror of
https://github.com/CCLeonOS/LeonOS.git
synced 2026-03-03 15:17:01 +00:00
fix(wget): 确保常用模块加载并改进代码执行方式
添加对常用模块的检查加载,并使用pcall安全执行下载的代码以避免直接崩溃
This commit is contained in:
@@ -31,11 +31,19 @@ end
|
|||||||
|
|
||||||
if args[1] == "run" then
|
if args[1] == "run" then
|
||||||
local data = get(args[2])
|
local data = get(args[2])
|
||||||
-- 确保fs模块已加载
|
-- 确保常用模块已加载
|
||||||
if not _G.fs then
|
if not _G.fs then _G.fs = require("fs") end
|
||||||
_G.fs = require("fs")
|
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
|
end
|
||||||
assert(load(data, "=<wget-run>", "t", _G))()
|
assert(pcall(func))
|
||||||
else
|
else
|
||||||
local filename = args[2] or (args[1]:match("[^/]+$")) or
|
local filename = args[2] or (args[1]:match("[^/]+$")) or
|
||||||
error("could not determine file name", 0)
|
error("could not determine file name", 0)
|
||||||
|
|||||||
Reference in New Issue
Block a user