Warning: this is an htmlized version!
The original is here, and
the conversion rules are here.
-- This file:
--   http://anggtwu.net/LUA/CoroRepl1.lua.html
--   http://anggtwu.net/LUA/CoroRepl1.lua
--          (find-angg "LUA/CoroRepl1.lua")
-- Author: Eduardo Ochs <eduardoochs@gmail.com>
--
-- (defun e () (interactive) (find-angg "LUA/CoroRepl1.lua"))
-- (find-es "lua5" "cow-and-coy")
--
-- «.CoroRepl»	(to "CoroRepl")

sprint = function (...)
    local args = pack(...)
    return mapconcat(tostring, args, "\t", args.n).."\n"
  end


-- «CoroRepl»  (to ".CoroRepl")

CoroRepl = Class {
  type    = "CoroRepl",
  __index = {
    write_ = function (c,s)   io.write(s) end,
    print_ = function (c,...) print(...) end,
    read_  = function (c)     return io.read() end,
    --
    dumps  = function (c)
        local f = mytostring
        local d = format("[i=%s o=%s p=%s]", f(c.i), f(c.o), f(c.p))
        return (d:gsub("\\\n", "|"))
      end,
    dumpw  = function (c)     io.write(c:dumps().." ") end,
    clr    = function (c)     c.i,c.o,c.p = nil,nil,nil end,
    dumpwc = function (c)     c:dumpw(); c:clr() end,
    iop    = function (c)     return {i=c.i, o=c.o, p=c.p} end,
    --
    writep = function (c,p)                         c:write_(p) end,
    writeo = function (c,o)   c.o = (c.o or "")..o; c:write_(o) end,
    printo = function (c,...) c:writeo(sprint(...)) end,
    read0  = function (c,p)   c:writep(p); return c:read_() end,
    read1  = function (c)     return c:read0("c> ")  end,
    read2  = function (c)     return c:read0("c>> ") end,
    --
    repl   = function (c)
        while true do
          local a,b = c:read1(), c:read2()
          c:printo("Rec: "..bitrim(a)..","..bitrim(b))
          if b:match "stop" then break end
        end
      end,
  },
}

c0 = CoroRepl {}
c1 = CoroRepl {
    read0 = function (c,p)
        c:writep(p)
        c.p = p
        c:dumpwc()
        c.i = io.read()
        return c.i
      end,
}
c1 = CoroRepl {
    read0 = function (c,p)
        -- c:writep(p)
        c.p = p
        local i = coy(c:iop())
        c:clr()
        c.i = i
        return c.i
      end,
}


--[[
* (eepitch-lua51)
* (eepitch-kill)
* (eepitch-lua51)
dofile "CoroRepl1.lua"
c  = c0
c  = c1
c:repl()
 foo
  bar
 plic
  ploc
 qux
  stop



-- (find-es "lua5" "cow-and-coy")


f = cow(foo)
= type(f)
= f("foo")
= f("bar")
= f("plic")
= f("ploc")

f1 = print
= cow(foo)

for s in cow(foo) do print(s) end



--]]





-- Local Variables:
-- coding:  utf-8-unix
-- End: