python -m SimpleHTTPServer

版权声明:大家一起学习进步,有不对的请大家指出。 https://blog.csdn.net/liqiangxo/article/details/72772775

–lua本地资源热更新
–python -m SimpleHTTPServer 2121 开启一个本地的文件共享服务

function hotUpdate(ip,loadPath,path , fileName)
        if not fileName  then
            return dump("没了")
        end
        local url = "http://"..ip ..loadPath  .."/".. fileName .. ".lua"
        local request = network.createHTTPRequest(function(event)
            local request = event.request
            if event.name == "completed" then
                if path ~= "" then
                    --判断文件是否存在
                    if not cc.FileUtils:getInstance():isFileExist(device.writablePath.. loadPath .."/" .. fileName .. ".lua") then
                        cc.FileUtils:getInstance():createDirectory(device.writablePath..loadPath);
                    end
                    --将获取到的数据存成文件
                    request:saveResponseData(device.writablePath.. loadPath.."/" .. fileName .. ".lua")
                    package.loaded[path.."."..fileName]=nil
                    dump(path.."."..fileName)
                    self.reload_module(path.."."..fileName)
                else
                    request:saveResponseData(device.writablePath .. fileName .. ".lua")
                    package.loaded[fileName]=nil

                    self.reload_module(fileName)
                end
                dump(fileName.."完成")
                -- return self.hotUpdate(ip,loadPath,path , fileName)
            end
        end, url, "GET")
        request:start()
end
阅读更多
换一批

没有更多推荐了,返回首页