-- 定义文件路径 local filePath = "/storage/emulated/0/MT2/.FuHong/FuHong/FuHong.lua" -- 替换为你的文件路径 local filePath = gg.prompt({'文件'}, {filePath}, {'file'})[1] local function readFile(filePath) local file = io.open(filePath, "r") if not file then print("无法打开文件: " .. filePath) return nil end local content = file:read("*all") file:close() return content end local function isNativeVariable(var) local nativeKeywords = { "gg", "file", "type", "print", "assert", "pairs", "ipairs", "next", "require", "dofile", "pcall", "xpcall", "math", "string", "table", "os", "io", "_G", "_VERSION", "coroutine", "debug", "utf8", "function", "json" } for _, keyword in ipairs(nativeKeywords) do if var == keyword or var:match("^" .. keyword) then return true end end return false end local function extractVariables(content) local variables = {} for var in content:gmatch("local%s+([%a_][%w_]*)") do if not variables[var] and not isNativeVariable(var) then variables[var] = true end end for var in content:gmatch("([%a_][%w_]*)%s*=%s*[^=]") do if not variables[var] and not isNativeVariable(var) then variables[var] = true end end return variables end local function insertVariablesToFile(filePath, variables) local fileContent = readFile(filePath) if not fileContent then return end local newContent = "" for var, _ in pairs(variables) do newContent = newContent .. '_ENV["' .. var .. '"] = nil\n' end newContent = newContent .. '\n' .. fileContent local file = io.open(filePath..'.lua', "w") if file then file:write(newContent) file:close() print("文件更新成功") else print("无法写入文件") end end local content = readFile(filePath) if not content then return end local variables = extractVariables(content) if next(variables) then insertVariablesToFile(filePath, variables) else print("没有找到变量定义") end