mirror of
https://github.com/leafo/moonscript.git
synced 2024-11-22 02:44:23 +00:00
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:
parent
8c2be55dbb
commit
3320932c71
@ -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)
|
||||||
|
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user