在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
热更新主要用于不停机修复bug等。故其重点是更新逻辑代码。 module(..., package.seeall) function funca() print("a33") end
模块b module(..., package.seeall) local atb = require "a" function funcb() atb.funca() end
主程序 local tbb = require "b" local atbb = require "a" local function reloadmodule(modulename) local oldmodule = _G[modulename] for k, v in pairs(oldmodule) do oldmodule[k] = nil end _G[modulename] = nil package.loaded[modulename] = nil require(modulename) local newmodule = _G[modulename] for k, v in pairs(newmodule) do oldmodule[k] = v end oldmodule._M = oldmodule _G[modulename] = oldmodule package.loaded[modulename] = oldmodule oldmodule = nil newmodule = nil end collectgarbage("collect") print(collectgarbage("count") * 1024) tbb.funcb() print("a tb: ", atbb) os.execute("pause") reloadmodule("a") tbb.funcb() print("a tb: ", atbb) collectgarbage("collect") print(collectgarbage("count") * 1024)
|
请发表评论