美文网首页
quick 实现热更之后重新加载lua脚本

quick 实现热更之后重新加载lua脚本

作者: 咸鱼而已 | 来源:发表于2017-05-26 15:58 被阅读318次

lua中通过require导入的文件,最终都存在package.loaded这个table中。
require会判断是否文件已经加载避免重复加载同一文件
所以需要先把package.loaded中对应的内容置空,然后再重新导入

    local reTab = {}
    for key,val in pairs(package.loaded) do
        if string.sub(key,1,4) == "app/" or string.sub(key,1,4) == "app." or key == "config" then           
            if key ~= "app/views/LoginScene" then
                package.loaded[key] = nil
                reTab[#reTab + 1] = key
                --print("key<<",key)
            end
        end
    end

相关文章

网友评论

      本文标题:quick 实现热更之后重新加载lua脚本

      本文链接:https://www.haomeiwen.com/subject/kkrxfxtx.html