I think that what they want is a command that restarts the program and runs the main loop so something like this would work better:
local cmd = io.read()
if cmd == "exit" then
dofile("thisfilename.lua")
end
I have been making simelar it isn't perfect but works