% test/sentences_lua.tex
% Cesure en contexte de paragraphe, via un callback LuaTeX
% post_linebreak_filter -- capture TOUTES les lignes composees, y
% compris celles qui ne declenchent ni Overfull ni Underfull (angle
% mort confirme de l'approche pdfTeX pure, voir docs/methodology.md).
%
% IMPORTANT : aucun commentaire Lua ("--") a l'interieur du bloc
% \directlua ci-dessous -- confirme par execution reelle que cela
% corrompt silencieusement l'execution du chunk (voir
% docs/methodology.md, aucune erreur visible n'est emise).
%
% Compilation : luatex -interaction=nonstopmode sentences_lua.tex
% Extraction  : python3 ../scripts/extract_hyphenation.py \
%                 sentences_lua.log out.txt --mode lua
\catcode`\@=11
\input plain

\directlua{
  local malagasy = lang.new(1)
  malagasy:patterns([[
.a1li1ka. .a1m2bo1ny. .a1m2pi1a1n2go1na1na. .a1n2ga1no. .a1n2ki1zy.
.fa1ha1sa1la1ma1na. .fa1n2ja1ka1na. .fi1a1na1ra1na. .ha1n2t2sa1na. .ha1zo.
.he1n2d2ry. .ke1li9ke1ly. .m2pa1n2ja1ka. .m2pi1a1na1t2ra. .ma1ha1fi1na1ri1tra.
.ma1n2de1ha. .ma1n2ka1fy. .mo1fo. .o1m2by. .ra1no. .ra1no1ma1si1na. .so1a.
.t2ra1n2d2ra1ka. .t2ra1no. .t2sa1ra. .va1o9va1o. .va1ry. .vo1a1ja1na1ha1ry. .vo1la.
]])

  local function glyph_to_chars(n, parts)
    if n.components then
      local c = n.components
      while c do
        glyph_to_chars(c, parts)
        c = c.next
      end
    else
      table.insert(parts, string.char(n.char))
    end
  end

  local function line_to_text(head)
    local parts = {}
    for n in node.traverse(head) do
      if n.id == node.id("glyph") then
        glyph_to_chars(n, parts)
      elseif n.id == node.id("disc") then
        table.insert(parts, "-")
      elseif n.id == node.id("glue") then
        table.insert(parts, " ")
      end
    end
    return table.concat(parts)
  end

  callback.register("post_linebreak_filter", function(head, groupcode)
    for line in node.traverse_id(node.id("hlist"), head) do
      texio.write_nl("LINE: " .. line_to_text(line.head))
    end
    return true
  end)
}

\language1
\lefthyphenmin=2
\righthyphenmin=2
\hsize=3cm
\pretolerance=-1
\tolerance=1000
\uchyph1

\noindent
Ny mahafinaritra dia ny fianarana momba ny trandraka sy ny mpianatra
any amin'ny fanjakana malagasy.
\par

\bye
