It's a case in the book programming in Lua. The code is followed, my question is why it can't get the last word of the line?
function allwords()
local line=io.read()
local pos=1
return function ()
while line do
local s,e=string.find(line,"%w+ ",pos)
if s then
pos=e+1
return string.sub(line,s,e)
else
line=io.read()
pos=1
end
end
return nil
end
end
for word in allwords() do
print(word)
end