Name: Anonymous 2012-03-11 19:41
probably the most popular Western text board on the Web.
#!/usr/bin/lua
local function line_is_empty(str)
return str == '' or str:match('^%s*$')
end
local function filter_file(input, output)
local loop
loop = function(previous_line, current_line)
if current_line == nil then
output(previous_line .. '\n')
elseif line_is_empty(previous_line) or line_is_empty(current_line) then
output(previous_line .. '\n')
loop(current_line, input())
else
output(previous_line .. ' ')
loop(current_line, input())
end
end
local first_line = input()
if first_line ~= nil then
loop(first_line, input())
end
end
local function main()
filter_file(io.lines(), function(str) io.write(str) end)
end
main()
$ cat s.lua | s.lua
#!/usr/bin/lua
local function line_is_empty(str) return str == '' or str:match('^%s*$') end
local function filter_file(input, output) local loop loop = function(previous_line, current_line) if current_line == nil then output(previous_line .. '\n') elseif line_is_empty(previous_line) or line_is_empty(current_line) then output(previous_line .. '\n') loop(current_line, input()) else output(previous_line .. ' ') loop(current_line, input()) end end local first_line = input() if first_line ~= nil then loop(first_line, input()) end end
local function main() filter_file(io.lines(), function(str) io.write(str) end) end
main()
$