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

View File

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