Lua not producing table of functions (IO API)

Posted by ArtOfCode on Stack Overflow See other posts from Stack Overflow or by ArtOfCode
Published on 2014-06-10T21:21:42Z Indexed on 2014/06/10 21:24 UTC
Read the original article Hit count: 123

Filed under:
|

I'm working on a basic project in Lua. I've been trying to get data from files using the IO API (as defined here), but when I open a file and give it a handle, it doesn't seem to return a table of functions.

The (erroneous bit of) code:

local unread = fs.list("email/"..from.."/")
local send = ""
for _,file in ipairs(unread) do
    local handle = io.open(file,"r")
    local text = handle:read("*a")
    send = send .. text .. "\n"
    handle.close()
    fs.delete(file)
end

The fs you see on the first line is a professional filesystem wrapper round the IO API, not my work and perfectly error-free, so that's not the problem. However, when I try to read the file (handle:read()), it throws "attempt to index nil". Tracing it, it turns out that handle itself is nil. Any ideas?

© Stack Overflow or respective owner

Related posts about table

Related posts about lua