使用url下载模块

时间:2017-10-16 21:24:53

标签: lua download corona

network.download(  url, "GET", function(e)
if (e.isError == false) then
    print("Download Successful")

    -- get the path of the downloaded file
    local path = system.pathForFile( "MyModule.lua" , system.TemporaryDirectory )

    -- Replace "/" with "." because that's how "require" works
    local newPath = string.gsub( path, "/", "." )

    -- Load the module
    local m = require ( newPath )   <<-- Error!

end
end, "MyModule.lua", system.TemporaryDirectory )

正如您所看到的,我尝试从网址下载模块。该文件确实被下载但是当尝试使用require函数加载它时,我收到此错误:

File: module '<<path of the file>>.tmp.MyModule.lua' not found

1 个答案:

答案 0 :(得分:0)

查看此主题 - https://forums.coronalabs.com/topic/27060-requiring-lua-file-from-documents-directory/

好像您在真实设备上无法require / loadstring