always call close() in lua when you're done with a file.

This commit is contained in:
Enno Rehling 2016-09-11 19:28:25 +02:00
parent cb36224e30
commit fdb5ecc68b
5 changed files with 75 additions and 63 deletions

View File

@ -39,13 +39,17 @@ local function read_players()
-- return {{ email = "noreply@mailinator.com", race = "dwarf", lang = "de" }}
local players = {}
local input = io.open("newfactions", "r")
while input do
if input then
local str = input:read("*line")
while str do
if str==nil then break end
local email, race, lang = str:match("([^ ]*) ([^ ]*) ([^ ]*)")
if email and string.char(string.byte(email, 1))~='#' then
table.insert(players, { race = race, lang = lang, email = email })
end
str = input:read("*line")
end
input:close()
end
return players
end

View File

@ -23,6 +23,7 @@ function cursed.init()
if f then
print("found cursed.txt")
curse(f)
f:close()
end
end

View File

@ -124,6 +124,7 @@ end
function seed()
local input = io.open(config.basepath .. "/parteien.txt")
if input then
for f in factions() do
if f.race=="vampunicorn" then
local str = input:read("*line")
@ -149,6 +150,8 @@ function seed()
end
end
end
input:close()
end
for r in regions() do
r:set_resource("sapling", r:get_resource("tree")/4)
r:set_resource("seed", 0)

View File

@ -27,6 +27,7 @@ else
end
local f=assert(io.open("factions", "r"))
if f then
line=f:read("*line")
players = {}
emails = {}
@ -47,7 +48,8 @@ while line~=nil do
players[email] = { ['lang'] = lang, ['race'] = race }
nplayers = nplayers + 1
end
f:close()
end
for k, r in ipairs(homes) do
print(k, r)
end

View File

@ -27,6 +27,7 @@ else
end
local f=assert(io.open("factions", "r"))
if f then
line=f:read("*line")
players = {}
emails = {}
@ -47,7 +48,8 @@ while line~=nil do
players[email] = { ['lang'] = lang, ['race'] = race }
nplayers = nplayers + 1
end
f:close()
end
for k, r in ipairs(homes) do
print(k, r)
end