為觸控精靈/按鍵精靈等 Lua 腳本加入自動更新功能?本文完整示範:版本檢查機制、FTP 下載更新包、熱重載流程,附完整代碼邏輯與運行截圖。


local CURRENT_VERSION = "1.0.0"
local URL = "ftp://your.server/version.txt"
local function getRemoteVersion()
local content = http.get(URL) -- 或 ftp.get
if content then
local version, fileName = content:match("version=(%S+)\nfileName=(%S+)")
return version, fileName
end
return nil, nil
end

local remoteVer, fileName = getRemoteVersion()
if remoteVer and remoteVer > CURRENT_VERSION then
-- 下載更新檔
local ftp = require("ftp")
ftp.download(fileName, "/path/to/script/" .. fileName)
-- 熱重載
dofile("/path/to/script/" .. fileName)
print("已更新至 " .. remoteVer)
end

點擊觸控精靈右上角「重新整理」,腳本自動檢測、下載、套用更新,無需手動重啟。

