我对Lua完全不熟悉,我需要处理一些Lua代码。
我有下面的方法,在其中传递一个文件,我想以字符串的形式读取该文件的内容。
function readAll(file)
local io = require("io")
local f = io.open(file, "rb")
local content = f:read("*all")
f:close()
return content
end为此,我得到了:
Lua: Yield error: [string "myFile.lua"]:101: attempt to index a nil value (local 'f')此错误出现在该行上:
local content = f:read("*all")知道是什么导致的吗?
发布于 2017-09-19 13:55:44
此错误意味着io.open失败。想知道为什么,试一试
local f = assert(io.open(file, "rb"))或
local f,e = io.open(file, "rb")
if f==nil then print(e) return nil endhttps://stackoverflow.com/questions/46301960
复制相似问题