Close files explicitly when done

Even though files are automatically closed, per the manual
it takes "an unpredictable amount of time to happen".
This commit is contained in:
Nils Nordman 2012-04-27 20:36:39 +02:00 committed by leaf corcoran
parent 8c2be55dbb
commit 3320932c71
2 changed files with 4 additions and 0 deletions

View File

@ -49,6 +49,7 @@ moon_loader = function(name)
end
if file then
local text = file:read("*a")
file:close()
return loadstring(text, file_path)
else
return nil, "Could not find moon file"
@ -82,6 +83,7 @@ loadfile = function(fname)
return nil, err
end
local text = assert(file:read("*a"))
file:close()
return loadstring(text, fname)
end
dofile = function(fname)

View File

@ -50,6 +50,7 @@ moon_loader = (name) ->
if file
text = file\read "*a"
file\close!
loadstring text, file_path
else
nil, "Could not find moon file"
@ -74,6 +75,7 @@ loadfile = (fname) ->
file, err = io.open fname
return nil, err if not file
text = assert file\read "*a"
file\close!
loadstring text, fname
-- throws errros