[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Imitation of AWK in Lua 5.1 using a PC.
- From: Jay Carlson <nop@...>
- Date: Mon, 10 Jul 2017 21:12:59 -0400
On Jul 10, 2017, at 5:08 PM, Gavin Holt <holtgavin@gmail.com> wrote:
> I would be grateful for some advice about how to manage the ORS. You
> will see that for the last source line I avoid appending the ORS. However,
> if the last line doesn't generate any output I can't get back the previously
> output ORS!
Here’s a closure version? It seemed easier than the object version.
function ors_stream(ORS, output)
local needs_ors = false;
return function(s)
if needs_ors then output(ORS) end
needs_ors=true
output(s)
end
end
my_stream = ors_stream("\n----\n", io.write)
my_stream("hello, world")
my_stream("hello, again")
Jay