'Lua program will not run more than once

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")
lua


Solution 1:[1]

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())

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Egor Skriptunoff