local iterator
function allwords()
local state = {line = io.read(), pos = 1}
return iterator, state
end
function iterator(state)
while state.line do -- 若为有效行的内容就进入循环
-- 搜索下一个单词
local s, e = string.find(state.line, "%w+", state.pos)
if s then -- 找到一个单词
state.pos = e + 1
return string.sub(state.line, s, e)
else -- 没有找到单词
state.line = io.read() -- 尝试读取下一行
state.pos = 1
end
en