forked from mtcontrib/pipeworks
Fixed settings file leak and invalid io.close (#136)
Before, init.lua called io.open on pipeworks.worldpath..'/pipeworks_settings.txt' to see if it existed, but did not close the resulting file handle if it was found to exist. It instead erroneously called io.close() with no argument, which does nothing if the default output file is set to stdout, which it is. Now, the result of io.open is saved to a local variable. If that value is not nil (i.e. if the world settings file exists), the file handle is passed to io.close before calling dofile. Also, this saves pipeworks.worldpath..'/pipeworks_settings.txt' to a local variable to reduce redundancy.
This commit is contained in:
parent
649c7d79f6
commit
10bfa30b93
8
init.lua
8
init.lua
@ -16,9 +16,11 @@ pipeworks.modpath = minetest.get_modpath("pipeworks")
|
|||||||
dofile(pipeworks.modpath.."/default_settings.txt")
|
dofile(pipeworks.modpath.."/default_settings.txt")
|
||||||
|
|
||||||
-- Read the external config file if it exists.
|
-- Read the external config file if it exists.
|
||||||
if io.open(pipeworks.worldpath.."/pipeworks_settings.txt","r") then
|
local worldsettingspath = pipeworks.worldpath.."/pipeworks_settings.txt","r"
|
||||||
dofile(pipeworks.worldpath.."/pipeworks_settings.txt")
|
local worldsettingsfile = io.open(worldsettingspath)
|
||||||
io.close()
|
if worldsettingsfile then
|
||||||
|
worldsettingsfile:close()
|
||||||
|
dofile(worldsettingspath)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Random variables
|
-- Random variables
|
||||||
|
Loading…
Reference in New Issue
Block a user