mirror of
https://github.com/TangentFoxy/.lua-files.git
synced 2024-11-20 21:34:23 +00:00
fix error by which utility.open might not always close file handles
This commit is contained in:
parent
33f9a123e6
commit
942a47330e
@ -133,9 +133,13 @@ utility.open = function(file_name, mode, custom_error_message)
|
||||
local file, err = io.open(file_name, mode)
|
||||
if not file then error(custom_error_message or err) end
|
||||
return function(fn)
|
||||
local result = fn(file)
|
||||
local success, result_or_error = pcall(function() return fn(file) end)
|
||||
file:close()
|
||||
return result
|
||||
if success then
|
||||
return result_or_error
|
||||
else
|
||||
error(result_or_error)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user