使用url下载模块
问题描述:
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)
正如您所看到的,我正在尝试从url下载模块。该文件确实被下载,但试图使用它的require
功能我得到这个错误时加载:使用url下载模块
File: module '<<path of the file>>.tmp.MyModule.lua' not found
答
对此话题一看 - https://forums.coronalabs.com/topic/27060-requiring-lua-file-from-documents-directory/
好像你不能在真实设备require
/loadstring
。