Reputation: 21
This is a program in Lua that is setup to grab a file and read to from the console, but it wont run more than once. I'm new to programing and I don't know what could keep it from running more than once. any help is appreciated
local function readfile(name)
io.input(name)
local file = io.read("*all")
io.close()
print (file)
end
local user = io.read()
readfile(user .. ".txt")
found the solution to the entire problum thanks to you all including Egor Skriptunoff for giving the fix to my function
local function readfile(name)
local f = assert(io.open(name))
local content = f:read("*all")
f:close()
return content
end
repeat
local input = io.read()
if string.sub(input, 1, 1) == ("@") then do
local ninput = string.sub(input, 2, 100)
print(readfile(ninput))
end
end
end
until input == ("stop")
Upvotes: 1
Views: 93
Reputation: 23767
io.input(name)
sets the input file (STDIN).
io.close()
closes the output file (STDOUT).
Probably you want to close the input file instead:
io.close(io.input())
Upvotes: 1