always read default_settings.txt before reading the world-folder's settings file
authorVanessa Ezekowitz <vanessaezekowitz@gmail.com>
Mon, 5 Aug 2013 08:36:50 +0000 (04:36 -0400)
committerVanessa Ezekowitz <vanessaezekowitz@gmail.com>
Mon, 5 Aug 2013 08:36:50 +0000 (04:36 -0400)
also close the file after copying.

init.lua

index 020db122f30248e831bd3f5923b82323fbbf02b4..306f64c07dc4551ea5472f7e2d3107e5326d152f 100644 (file)
--- a/init.lua
+++ b/init.lua
@@ -6,14 +6,14 @@
 -- License: WTFPL
 --
 
--- Copy and/or read the config file
+-- Read (and if necessary, copy) the config file
 
 local worldpath = minetest.get_worldpath()
 local modpath = minetest.get_modpath("pipeworks")
 
-if io.open(worldpath.."/pipeworks_settings.txt","r") == nil then
+dofile(modpath.."/default_settings.txt")
 
-       dofile(modpath.."/default_settings.txt")
+if io.open(worldpath.."/pipeworks_settings.txt","r") == nil then
 
        io.input(modpath.."/default_settings.txt")
        io.output(worldpath.."/pipeworks_settings.txt")
@@ -21,7 +21,10 @@ if io.open(worldpath.."/pipeworks_settings.txt","r") == nil then
        local size = 2^13      -- good buffer size (8K)
        while true do
                local block = io.read(size)
-               if not block then break end
+               if not block then
+                       io.close()
+                       break
+               end
                io.write(block)
        end