Warning: this is an htmlized version!
The original is across this link,
and the conversion rules are here.
-- This file:
-- http://angg.twu.net/dednat6/output.lua
-- http://angg.twu.net/dednat6/output.lua.html
--  (find-angg        "dednat6/output.lua")
--
-- Sending (Lua-produced) TeX code back to the TeX interpreter requires
-- some preprocessing... see:
--   (find-es "luatex" "comments-in-tex.print")
--   (find-es "luatex" "spurious-omega")
--
-- Usage:
--   \catcode`\^^J=10                     % (find-es "luatex" "spurious-omega")
--   \directlua{output = mytexprint}
--   \directlua{output =  printboth}
-- or: (...)

-- «.deletecomments»	(to "deletecomments")
-- «.output»		(to "output")
-- «.write_dnt_file»	(to "write_dnt_file")
-- «.formatt»		(to "formatt")
-- «.bprintt»		(to "bprintt")


-- «deletecomments» (to ".deletecomments")
-- (find-es "luatex" "comments-in-tex.print")
deletecomments = function (str)
    return (str:gsub("%%[^%%\n]*\n[ \t]*", ""))
  end


-- Old:
-- mytexprint = function (str)
--     tex.print(deletecomments(str))
--   end
-- printboth = function (str)
--     print("("..tf.nline.."):")
--     print(str)
--     mytexprint(str)
--   end


-- New:
-- «output»         (to ".output")
-- «write_dnt_file» (to ".write_dnt_file")
--
dnt_log = ""
--
output_quiet = function (str)
    dnt_log = dnt_log..str.."\n"
    tex.print(deletecomments(str))
  end
output_verbose = function (str)
    print("("..tf.nline.."):")
    print(str)
    output_quiet(str)
  end
output  = output_quiet
quiet   = function () output = output_quiet end
verbose = function () output = output_verbose end
--
write_dnt_file  = function ()
    local fname = tex.jobname..".dnt"
    writefile(fname, dnt_log)
    print("(Wrote: "..fname..")")
  end




-- «formatt» (to ".formatt")
formatt = function (...)
    local A = {...}
    for i=1,#A do if type(A[i]=="table") then A[i] = tostring(A[i]) end end
    return format(unpack(A))
  end
printt  = function (...) print(formatt(...)) end
outputt = function (...) output(formatt(...)) end


-- «bprintt» (to ".bprintt")
-- Usage in the REPL:
--   bprint, out = makebprint("verbose")
--   bprint("%s--%s", v(2,3), v(4,5))
--   bprint("%s--%s", v(20,30), v(40,50))
--   = out()
-- Usage in a function:
--   local bprint, out = makebprint()
--   bprint("%s--%s", v(2,3), v(4,5))
--   bprint("%s--%s", v(20,30), v(40,50))
--   return out()
makebprint = function (verbose)
    local buffer = {}
    local bprint = function (...) table.insert(buffer, formatt(...)) end
    local out    = function () return table.concat(buffer, "\n") end
    if verbose then
      local bprint0 = bprint
      bprint = function (...) printt(...); bprint0(...) end
    end
    return bprint, out, buffer
  end




--[[
* (eepitch-lua51)
* (eepitch-kill)
* (eepitch-lua51)
dofile "output.lua"

--]]


-- Local Variables:
-- coding: raw-text-unix
-- End: