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")
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 })
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,30 +124,33 @@ end
function seed()
local input = io.open(config.basepath .. "/parteien.txt")
for f in factions() do
if f.race=="vampunicorn" then
local str = input:read("*line")
if str==nil then break end
local race, lang, email = str:match("([^ ]*) ([^ ]*) ([^ ]*)")
f.race = race:lower()
f.options = f.options + 4096
f.email = email
f.locale = lang
for u in f.units do
u.race = race:lower()
u.hp = u.hp_max
local b = building.create(u.region, "castle")
if lang=="de" then
u.name = "Entdecker"
b.name = "Heimat"
else
u.name = "Explorer"
b.name = "Home"
if input then
for f in factions() do
if f.race=="vampunicorn" then
local str = input:read("*line")
if str==nil then break end
local race, lang, email = str:match("([^ ]*) ([^ ]*) ([^ ]*)")
f.race = race:lower()
f.options = f.options + 4096
f.email = email
f.locale = lang
for u in f.units do
u.race = race:lower()
u.hp = u.hp_max
local b = building.create(u.region, "castle")
if lang=="de" then
u.name = "Entdecker"
b.name = "Heimat"
else
u.name = "Explorer"
b.name = "Home"
end
b.size = 10
u.building = b
end
end
b.size = 10
u.building = b
end
end
input:close()
end
for r in regions() do
r:set_resource("sapling", r:get_resource("tree")/4)

View File

@ -27,27 +27,29 @@ else
end
local f=assert(io.open("factions", "r"))
line=f:read("*line")
players = {}
emails = {}
patrons = {}
nplayers = 0
while line~=nil do
fields = {}
line:gsub("([^\t]*)\t*", function(c) table.insert(fields, c) end)
if f then
line=f:read("*line")
email = fields[1]
if fields[2]=='yes' then
table.insert(patrons, email)
else
table.insert(emails, email)
players = {}
emails = {}
patrons = {}
nplayers = 0
while line~=nil do
fields = {}
line:gsub("([^\t]*)\t*", function(c) table.insert(fields, c) end)
line=f:read("*line")
email = fields[1]
if fields[2]=='yes' then
table.insert(patrons, email)
else
table.insert(emails, email)
end
if fields[3]=='German' then lang='de' else lang='en' end
race=string.gsub(fields[4], "/.*", ''):lower()
players[email] = { ['lang'] = lang, ['race'] = race }
nplayers = nplayers + 1
end
if fields[3]=='German' then lang='de' else lang='en' end
race=string.gsub(fields[4], "/.*", ''):lower()
players[email] = { ['lang'] = lang, ['race'] = race }
nplayers = nplayers + 1
f:close()
end
for k, r in ipairs(homes) do
print(k, r)
end

View File

@ -27,27 +27,29 @@ else
end
local f=assert(io.open("factions", "r"))
line=f:read("*line")
players = {}
emails = {}
patrons = {}
nplayers = 0
while line~=nil do
fields = {}
line:gsub("([^\t]*)\t*", function(c) table.insert(fields, c) end)
if f then
line=f:read("*line")
email = fields[1]
if fields[2]=='yes' then
table.insert(patrons, email)
else
table.insert(emails, email)
players = {}
emails = {}
patrons = {}
nplayers = 0
while line~=nil do
fields = {}
line:gsub("([^\t]*)\t*", function(c) table.insert(fields, c) end)
line=f:read("*line")
email = fields[1]
if fields[2]=='yes' then
table.insert(patrons, email)
else
table.insert(emails, email)
end
if fields[3]=='German' then lang='de' else lang='en' end
race=string.gsub(fields[4], "/.*", ''):lower()
players[email] = { ['lang'] = lang, ['race'] = race }
nplayers = nplayers + 1
end
if fields[3]=='German' then lang='de' else lang='en' end
race=string.gsub(fields[4], "/.*", ''):lower()
players[email] = { ['lang'] = lang, ['race'] = race }
nplayers = nplayers + 1
f:close()
end
for k, r in ipairs(homes) do
print(k, r)
end