使用url下载模块

network.download(  url, "GET", function(e)
if (e.isError == false) then
    print("下载成功")

    -- 获取已下载文件的路径
    local path = system.pathForFile( "MyModule.lua" , system.TemporaryDirectory )

    -- 将路径中的"/"替换为".",因为"require"函数是这样工作的
    local newPath = string.gsub( path, "/", "." )

    -- 加载模块
    local m = require ( newPath )   <<-- 错误!

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

正如你所见,我在尝试从url下载一个模块。文件确实被下载了,但是当我试着使用require函数加载它时,我得到了这个错误:

文件:'<<文件路径>>.tmp.MyModule.lua' 模块未找到
点赞
用户5331361
用户5331361

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

看起来你不能在真实设备上使用 require / loadstring

2017-10-19 10:34:24