Warning: this is an htmlized version!
The original is here, and
the conversion rules are here.
-- This file:
--   http://anggtwu.net/LUA/TocLines2.lua.html
--   http://anggtwu.net/LUA/TocLines2.lua
--          (find-angg "LUA/TocLines2.lua")
-- Author: Eduardo Ochs <eduardoochs@gmail.com>
--
-- (defun tl  () (interactive) (find-angg "LUA/TocLines2.lua"))
-- (defun tlo () (interactive) (find-angg "LUA/TocLines1.lua"))
--
-- Used in:
--   (find-LATEX "2024-1-C2-intro.tex" "defs-toclines")
--   (find-LATEX "2024-1-C2-intro.tex" "writetoc")
--   (c2m241introp 2 "toc")
--   (c2m241introa   "toc")
--   (find-LATEX "2024-1-C3-intro.tex" "defs-toclines2")

-- (find-Deps1-links "TocLines2")
-- (find-Deps1-cps   "TocLines2")
-- (find-Deps1-anggs "TocLines2")

-- «.TocLines»			(to "TocLines")
-- «.TocLines-tests»		(to "TocLines-tests")
-- «.dednat6»			(to "dednat6")
-- «.dednat6-tests»		(to "dednat6-tests")

require "Show2"    -- (find-angg "LUA/Show2.lua")

--  _____          _     _                 
-- |_   _|__   ___| |   (_)_ __   ___  ___ 
--   | |/ _ \ / __| |   | | '_ \ / _ \/ __|
--   | | (_) | (__| |___| | | | |  __/\__ \
--   |_|\___/ \___|_____|_|_| |_|\___||___/
--                                         
-- «TocLines»  (to ".TocLines")

TocLines = Class {
  type   = "TocLines",
  new    = function (fname) return TocLines {fname=fname} end,
  fmts   = VTable {}, 
  __tostring = function (tls) return tls:totex() end,
  __index = {
    add     = function (tls, o) table.insert(tls, o); PP(o) end,
    getfmt  = function (tls, style) return TocLines.fmts[style] end,
    format  = function (tls, o)     return tls:format0(o, tls:getfmt(o.style)) end,
    format0 = function (tls, o, fmt)
        local f = function (s) return o[s] end
        return (fmt:gsub("<(.-)>", f))
      end,
    totex   = function (tls)
        local f = function (i)
            if type(tls[i]) == "string" then return tls[i] end
            return tls:format(tls[i])
          end
        return mapconcat(f, seq(1, #tls), "")
      end,
    --
    tocbody    = function (tls) return "\n"..tls:totex().."\n" end,
    tocfname   = function (tls) return tls:fnamestem()..".mytoc" end,
    fnamestem  = function (tls)
        return (tls.fname:gsub("%.tex$", ""):gsub("%.mytoc$", ""))
      end,
    writetoc   = function (tls)
        ee_writefile(tls:tocfname(), tls:tocbody())
        print("Writing: "..tls:tocfname())
        return tls
      end,
  },
}

-- «TocLines-tests»  (to ".TocLines-tests")
--[==[
* (eepitch-lua51)
* (eepitch-kill)
* (eepitch-lua51)
dofile "TocLines2.lua"

tls = TocLines.new("/tmp/toclines2-test.tex")
TocLines.fmts["slide"] = "_<page>_<body>_\n"
tls:add {style="slide", page=2, body="Links"}
tls:add {style="slide", page=3, body="Intro"}
tls:add "BLA\n"
tls:add {style="slide", page=4, body="More stuff"}

= tls:getfmt("slide")
= tls:format(tls[1])
= tls:format(tls[2])
= tls:format(tls[4])
= tls:totex()
= tls:tocbody()
= tls:fnamestem()
= tls:tocfname()
= tls:writetoc()

TocLines.fmts["slide"] = "\\mytocline{<page>}{<body>}\n"
= tls:totex()

--]==]



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

dednat6_toclines2 = [==[
%L dofile "TocLines2.lua"
%L toclines = TocLines.new(status.filename)
%L TocLines.fmts["slide"] = "\\toclineslidetex{<body>}{<page>}\n"
\pu
\def\toclineslidetex#1#2{\par #1 \dotfill #2}
\def\toclineslidelua#1#2{\directlua{
    toclines:add {style="slide", body=[=[#1]=], page=#2}
  }}
\def\SLIDE#1{
  \par{\bf #1}\par
  \toclineslidelua{#1}{\thepage}
}
]==]

-- «dednat6-tests»  (to ".dednat6-tests")
--[==[
* (find-Deps1-cps "TocLines2")
* (find-sh0 "rm -fv ~/LATEX/Show2.mytoc")
* (show2-use       "~/LATEX/Show2.tex")
* (eepitch-lua51)
* (eepitch-kill)
* (eepitch-lua51)
dofile "TocLines2.lua"
usepackages.hyperref = true
dednat6["0"] = true
dednat6.toclines2 = true

body = [=[
  % From: (find-fline "~/LATEX/Show2.mytoc")
  \toclineslidetex{One}{2}
  \toclineslidetex{Two}{3}
  %
  \newpage \SLIDE{One}
  \newpage \SLIDE{Two}
  %
  \directlua{ toclines:writetoc() }
  % See: (find-fline "~/LATEX/Show2.mytoc")
]=]
= body:show0()
= body:show()
* (etv)

--]==]





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