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)