David Kastrup
Hans Hagen
writes: David Kastrup wrote:
in the following code, the callback is never reached when called with luatex -ini bug
you return nothing, while you need to return a table with at least a reader function that luatex can call for each line it wants
I am aware of that. The above code is not intended to work, but rather to produce a noticeable message (of course, this is a minimal example: the actual use case did something more useful), possibly bombing out afterwards.
It does not do that: the callback is never reached in the first place.
For what it is worth: here is the actual code I use. Adding the callback for find_read_file (as Taco suggested as a workaround) makes this work as expected. Without adding the callback, it does not work, contrary to the documentation. \begingroup \catcode `\{1 \catcode `\}2 \catcode `\@11 \catcode `\#=6 \catcode `\%=14 \gdef\lu@@inpencsetup{% \directlua0{ inputenc={auto = function(line) return line end; bytes = function(line) return unicode.utf8.char(unicode.latin1.byte(line,0,-1)) end }; callback.register("find_read_file", function(id,filename) return kpse.find_file(filename, "tex", true) end); callback.register("open_read_file", function(filename) local file = io.open(filename, "rb"); return {file = file; inputenc = defaultinputenc; reader = function(table) if localinputenc then table.inputenc = localinputenc; localinputenc = nil end; local line = table.file:read(); if line then return table.inputenc(line) else return nil end end; close = function(table) table.file:close() end} end)}} \lu@@inpencsetup \protected\gdef\XeTeXinputencoding"#1"{\directlua0{ localinputenc=inputenc["#1"]}} \protected\gdef\XeTeXdefaultencoding"#1"{\directlua0{ defaultinputenc=inputenc["#1"]}} \global\let\lu@@dump\dump \protected\gdef\dump{\everyjob \expandafter{\the\everyjob \lu@@inpencsetup\XeTeXdefaultencoding "bytes"} \lu@@dump} \endgroup \XeTeXdefaultencoding "bytes" \input latex.ltx -- David Kastrup