Hello,
take this plain LuaTeX example:
\setbox0=\hbox{\pdfextension literal{0 g}}
% 1)
\directlua{
local literal = tex.getbox(0).head
texio.write_nl("log", "literal.data="..literal.data)
}
\showbox0
% 2)
\directlua{
local literal = tex.getbox(0).head
literal.data = "test"
literal.token = "toks"
texio.write_nl("log", "literal.token="..(literal.token or "nil"))
}
\showbox0
% 3) patch test
\directlua{
tex.set("everyjob", "asd")
texio.write_nl("log", tex.get("everyjob"))
}
\bye
Expected log output (abridged):
1)
literal.data=0 g
.\pdfliteral origin{0 g}
2)
literal.token=toks
.\pdfliteral origin{toks}
Actual output:
1)
literal.data=data
.\pdfliteral origin{0 g}
2)
literal.token=characters
.\pdfliteral origin <lua data reference 153>
In the first case the Lua accessor returns a value which happens to be
on top of the stack (the key "data" itself). In the second case an index
into TeX memory is misinterpreted as a Lua registry index, so the
returned data is essentially garbage.
Patch for both issues is attached. I also extended `tokenlist_from_lua`
(which is what `nodelib_gettoks` is defined as) to allow an index
argument. The previous version used the value on top of the stack, which
probably worked for every use currently in LuaTeX, but seemed rather
dangerous and subtle.
The patch is from git, though it can be applied normally with
patch -Np1 < pdf_literal.patch
Kind regards,
Michal Vlasák