From 311b49a3e5284dd4cc549717d9de2e7b9bca4691 Mon Sep 17 00:00:00 2001 From: Leonmmcoset Date: Sun, 31 Aug 2025 20:51:29 +0800 Subject: [PATCH] =?UTF-8?q?fix(wget):=20=E7=A1=AE=E4=BF=9D=E5=B8=B8?= =?UTF-8?q?=E7=94=A8=E6=A8=A1=E5=9D=97=E5=8A=A0=E8=BD=BD=E5=B9=B6=E6=94=B9?= =?UTF-8?q?=E8=BF=9B=E4=BB=A3=E7=A0=81=E6=89=A7=E8=A1=8C=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 添加对常用模块的检查加载,并使用pcall安全执行下载的代码以避免直接崩溃 --- data/computercraft/lua/rom/programs/wget.lua | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/data/computercraft/lua/rom/programs/wget.lua b/data/computercraft/lua/rom/programs/wget.lua index 606b98b..dc95568 100644 --- a/data/computercraft/lua/rom/programs/wget.lua +++ b/data/computercraft/lua/rom/programs/wget.lua @@ -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, "=", "t", _G) + if not func then + error("Failed to load downloaded code: " .. err, 0) end - assert(load(data, "=", "t", _G))() + assert(pcall(func)) else local filename = args[2] or (args[1]:match("[^/]+$")) or error("could not determine file name", 0)