-
Notifications
You must be signed in to change notification settings - Fork 383
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"for line in openedfile:lines() do" fails in 2.x #995
Comments
Yeah, seems like a bug in either the version of NLua we're using, or whatever lua it's interfacing to (the project seems to contain lua51.dll and KopiLua?) and for that matter also LuaInterface.dll, despite nlua being a fork of that. I actually have no idea what we're using in general for lua, other than that in theory it's supposed to work as 5.1 but file i/o is broken as heck; Here's a really nasty hackjob fix I guess... function io.lines(filename)
local f = io.open(filename, "r")
local iterator = function(f, prevLine)
local success, line = pcall(function()
return f:read("*l"):gsub("\n",""):gsub("\r","")
end)
if not success or line == nil then
f:close()
line = nil
end
return line
end
return iterator, f, ""
end
function GuiLoadSettings()
for line in io.lines("config.cfg") do
print(line)
end
end
GuiLoadSettings()
while true do
print("hello world")
emu.frameadvance()
end |
Thank you, this works nicely. As a FYI, it will crash if the cfg file is missing but I adjusted my code and it works now with and without cfg file. function doLine(filename)
local f = io.open(filename, "r")
local iterator = function(f, prevLine)
if f==nil then
return nil
else
local success, line = pcall(function()
return f:read("*l"):gsub("\n",""):gsub("\r","")
end)
if not success or line == nil then
f:close()
line = nil
end
return line
end
end
return iterator, f, ""
end |
config > customize > advanced > lua+luainterface |
Don't remove kopilua just yet, @FelipeLopes might need it. |
KopiLua was removed in 45fbdb4, KeraLua works fine here. |
I explained my issue here: http://tasvideos.org/forum/viewtopic.php?p=458352#458352
If you open a file with
io.open()
and then runfor line in openedfile:lines() do
on it, it will output an error. It does not happen in the 1.x versions.The text was updated successfully, but these errors were encountered: