RosettaCodeData/Task/Reverse-words-in-a-string/Lua/reverse-words-in-a-string-1...

10 lines
230 B
Lua

local lines = {}
for line in (s .. "\n"):gmatch("(.-)\n") do
local this = {}
for word in line:gmatch("%S+") do
table.insert(this, 1, word)
end
lines[#lines + 1] = table.concat(this, " ")
end
print(table.concat(lines, "\n"))