Posted 26 July 2016 - 04:02 PM
Hey there! I'm trying to make a bootloader, and I want to detect all .bmf on /dev, but line 83 gives me: "Attempt to index ? (a nil value)". I've been trying to troubleshoot the error, and I think it may be that fs.open is returning nil, but if that code gets to run, it means there is a file. Thanks in advance
local function toLines(readall)
local t = {}
local function helper(line) table.insert(t, line) return "" end
helper((readall:gsub("(.-]\r?\n", helper)))
return t
end
local function s(str, char)
sep = sep or "%s"
local l={}
for str in string.gmatch(str, "(.-)("..sep..")") do
table.insert(l,str)
end
return t
end
function sW(str, start)
return string.sub(str,1,string.len(Start))==Start
end
function eW(str, ends)
return ends=='' or string.sub(str, -string.len(ends))==ends
end
bmflist = {}
seltable = {1}
fsl = fs.list("/dev")
for _,fse in ipairs(fsl) do
print(fse) --Debug print
if eW(fse, ".bmf") then
bmf = fs.open(fse, "r") -- Debug print (THIS errors)
bmflist[fse] = {["rf"] = bmf} -- THIS errors
print(bmf.readAll())
bmflines = toLines(bmf.readAll())
for line in bmflines do
if sW(line, "-- entryName:") then
sline = s(line, ':')
bmflist[fse]["en"] = sline[2]
if sline[2] == "Shutdown" then
table.insert(seltable, 2)
else table.insert(seltable, 0) end
elseif sW(line, "-- description:") then
sline = s(line, ':')
bmflist[fse]["dc"] = sline[2]
elseif sW(line, "-- bmf:end") then break end
end
end
bmf.close()
term.setCursorPos(1,19)
if bmflist == {} then error("> No .bmf files found.") end
for k,v in bmflist do if v["en"] == nil then error("> .bmf file not registered.") end end
end