Various adaptions

This commit is contained in:
Marcel Krüger 2021-03-20 19:00:02 +01:00
parent 10add04b91
commit a6d3b3cc0f
11 changed files with 69 additions and 57 deletions

View File

@ -4,5 +4,5 @@ module = "luametalatex"
tdsroot = "luametatex" -- Would be luametalatex but we use the same files for luametaplain
installfiles = {"luameta*.lua", "luameta*.ini", "*.so", "*.dll", "luametatexconfig.tex", "luametalatex-ltexpl-hook.tex"}
sourcefiles = {"luameta*.lua", "luameta*.ini", "*.so", "*.dll", "luametatexconfig.tex", "luametalatex-ltexpl-hook.tex"}
installfiles = {"luameta*.lua", "luameta*.ini", "*.so", "*.dll", "*texconfig.tex", "luametalatex-ltexpl-hook.tex"}
sourcefiles = {"luameta*.lua", "luameta*.ini", "*.so", "*.dll", "*texconfig.tex", "luametalatex-ltexpl-hook.tex"}

View File

@ -148,7 +148,7 @@ local function write_infodir(p)
additional = string.format("%s/Creator(TeX)", additional)
end
if not string.find(infodir, "/PTEX.Fullbanner", 1, false) then
additional = string.format("%s/PTEX.Fullbanner(%s)", additional, status.banner)
additional = string.format("%s/PTEX.Fullbanner(%s)", additional, status.enginestate.banner)
end
return p:indirect(nil, string.format("<<%s%s>>", infodir, additional))
end
@ -226,7 +226,7 @@ function callbacks.stop_run()
local size = pfile:close()
texio.write_nl("term", "(see the transcript file for additional information)")
-- TODO: Additional logging, epecially targeting the log file
texio.write_nl("term and log", string.format(" %d words of node memory still in use:", status.var_used))
texio.write_nl("term and log", string.format(" %d words of node memory still in use:", status.nodestate.use))
local by_type, by_sub = {}, {}
for n, id, sub in node.traverse(node.usedlist()) do
if id == whatsit_id then
@ -245,7 +245,7 @@ function callbacks.stop_run()
end
texio.write_nl(" " .. table.concat(nodestat, ', '))
texio.write_nl(string.format("Output written on %s (%d pages, %d bytes).", pdfname, pages, size))
texio.write_nl(string.format("Transcript written on %s.\n", status.log_name))
texio.write_nl(string.format("Transcript written on %s.\n", status.enginestate.logfilename))
end
callbacks.__freeze('stop_run', true)
@ -569,7 +569,7 @@ local function write_colorstack()
local text
if action == "push" or "set" then
text = scan_string()
-- text = token.to_string(token.scan_tokenlist()) -- Attention! This should never be executed in an expand-only context
-- text = token.serialize(token.scan_tokenlist()) -- Attention! This should never be executed in an expand-only context
end
local whatsit = node.new(whatsit_id, colorstack_whatsit)
node.setproperty(whatsit, {
@ -893,11 +893,7 @@ token.luacmd("useimageresource", function()
imglib_write(pfile, img)
end, "protected")
local value_values = token.values'value'
for i=0,#value_values do
value_values[value_values[i]] = i
end
local integer_code = value_values.integer
local integer_code = token.value.integer
token.luacmd("lastsavedimageresourceindex", function()
return integer_code, lastimage

View File

@ -99,16 +99,17 @@ local do_terminal_input do
end
end
function callbacks.intercept_tex_error(mode, eof)
-- if eof then
-- print'EOF'
-- tex.runtoks(function()token.put_next(token.create'tracingall')end)
-- do_terminal_input()
-- tex.runtoks(token.skip_next)
-- return 3
-- end
local errorvalues = tex.geterrorvalues()
function callbacks.intercept_tex_error(mode, errortype)
errortype = errorvalues[errortype]
if errortype == "eof" then
tex.runlocal(function()token.put_next(token.create'tracingall')end)
do_terminal_input()
tex.runlocal(token.skip_next)
return 3
end
texio.write'.'
tex.show_context()
tex.showcontext()
if mode ~= 3 then return mode end
repeat
texio.write_nl'? '
@ -123,7 +124,7 @@ function callbacks.intercept_tex_error(mode, eof)
Maybe you should try asking a human?")
elseif first == 'I' then
line = line:sub(2)
tex.runtoks(function()
tex.runlocal(function()
tex.sprint(token.scan_token(), line)
end)
return 3

View File

@ -2,12 +2,8 @@ local scan_dimen = token.scan_dimen
local scan_int = token.scan_integer
local scan_keyword = token.scan_keyword
local value_values = token.values'value'
for i=0, #value_values do
value_values[value_values[i]] = i
end
local count_code = value_values.integer
local dimen_code = value_values.dimension
local count_code = token.value.integer
local dimen_code = token.value.dimension
local set_local = require'luametalatex-local'

View File

@ -6,15 +6,11 @@ local setters = {
}
local getters = {
}
local value_values = token.values'value'
for i=0,#value_values do
value_values[value_values[i]] = i
end
function tex.gettextdir() return tex.textdirection end
function tex.getlinedir() return tex.linedirection end
function tex.getmathdir() return tex.mathdirection end
function tex.getpardir() return tex.pardirection end
local integer_code = value_values.integer
local integer_code = token.value.integer
local function set_xdir(id, scanning)
if scanning == 'value' then
return integer_code, getters[id]()

View File

@ -1,4 +1,5 @@
local scan_int = token.scan_integer
token.scan_int = scan_int -- For compatibility with LuaTeX packages
local scan_token = token.scan_token
local scan_tokenlist = token.scan_tokenlist
local scan_keyword = token.scan_keyword
@ -7,6 +8,8 @@ local set_macro = token.set_macro
local callback_find = callback.find
local constants = status.getconstants()
local lua_call_cmd = token.command_id'lua_call'
local properties = node.direct.get_properties_table()
node.direct.properties = properties
@ -32,7 +35,7 @@ local function scan_filename()
tok = scan_token()
cmd = tok.command
until cmd ~= spacer_cmd and cmd ~= relax_cmd
while (tok.command <= 12 and tok.command > 0 and tok.command ~= 9 and tok.index <= token.biggest_char()
while (tok.command <= 12 and tok.command > 0 and tok.command ~= 9 and tok.index <= constants.max_character_code
or (token.put_next(tok) and false))
and (quoted or tok.index ~= string.byte' ') do
if tok.index == string.byte'"' then
@ -50,7 +53,7 @@ end
local initex_catcodetable = 1
local string_catcodetable = 2
if status.ini_version then
tex.runtoks(function()tex.sprint[[\initcatcodetable 1\initcatcodetable 2]]end)
tex.runlocal(function()tex.sprint[[\initcatcodetable 1\initcatcodetable 2]]end)
local setcatcode = tex.setcatcode
for i=0,127 do
setcatcode('global', 2, i, 12)
@ -135,7 +138,7 @@ token.luacmd("closein", function(_, prefix)
end, "value")
local function do_write(p)
local data = token.to_string(p.data)
local data = token.serialize(p.data)
local content = data and data .. '\n' or '\n'
local file = ofiles[p.file]
if file then
@ -198,7 +201,7 @@ token.luacmd("read", function(_, prefix)
error[[FIXME: Ask the user for input]]
end
local endlocal
tex.runtoks(function()
tex.runlocal(function()
endlocal = token.scan_next()
tex.sprint(endlocal)
tex.print(line and line ~= "" and line or " ")
@ -217,7 +220,7 @@ token.luacmd("read", function(_, prefix)
tokens[#tokens+1] = tok
end
if balance ~= 0 then error[[FIXME: Read additional input lines]] end
tex.runtoks(function()
tex.runlocal(function()
tokens[#tokens+1] = rbrace
token.put_next(tokens)
token.put_next(token.primitive_tokens.def, token.create(macro), lbrace)
@ -252,7 +255,7 @@ token.luacmd("readline", function(_, prefix)
end, "value")
local integer_code, boolean_code do
local value_values = token.values'value'
local value_values = token.getfunctionvalues()
for i=0,#value_values do
if value_values[i] == "integer" then
integer_code = i
@ -270,7 +273,7 @@ end, "condition")
local late_lua_whatsit = new_whatsit('late_lua', function(p, pfile, n, x, y)
local code = p.data
if not code then
code = token.to_string(p.token)
code = token.serialize(p.token)
end
if type(code) == 'string' then
code = assert(load(code, nil, 't'))
@ -289,6 +292,7 @@ end, "protected")
local functions = lua.get_functions_table()
require'luametalatex-meaning'
require'luametalatex-baseregisters'
require'luametalatex-back-pdf'
require'luametalatex-node-luaotfload'

View File

@ -32,3 +32,4 @@ for _, name in ipairs{
local value = var_value(name)
texconfig[name] = tonumber(value) or value or nil
end
texconfig.token_size = 10000000

View File

@ -24,6 +24,19 @@ do
end
end
kpse.set_program_name(arg.arg0 or arg[arg[0]], arg.progname)
do
local interaction = ({ [true] = 3, [false] = false,
batchmode=0,
nonstopmode=1,
scrollmode=2,
errorstopmode=3,
})[arg.interaction or false]
if interaction then
tex.setinteraction(interaction)
elseif interaction == nil then
texio.write('term', string.format('Unknown interaction mode %q ignored.\n', arg.interaction))
end
end
package.searchers[2] = function(modname)
local filename = kpse.find_file(modname, "lua", true)
if not filename then
@ -40,6 +53,7 @@ kpse.set_maketex("pk", true, "compile")
require'luametalatex-init-config'
local callback_register = callback.register
local build_bytecode
status.ini_version = status.run_state == 0
if status.ini_version then
local build_bytecode_mod = require'luametalatex-build-bytecode'
local preloaded_modules = {}
@ -55,19 +69,9 @@ if status.ini_version then
end
end
callback_register('find_format_file', function(name) return kpse.find_file(name, 'fmt', true) end)
callback_register('find_format_file', function(name) texconfig.formatname = kpse.find_file(name, 'fmt', true) return texconfig.formatname end)
-- texconfig.firstline = [[\show ]]
function texconfig.init()
local interaction = ({ [true] = 3, [false] = false,
batchmode=0,
nonstopmode=1,
scrollmode=2,
errorstopmode=3,
})[arg.interaction or false]
if interaction then
tex.setinteraction(interaction)
elseif interaction == nil then
texio.write('term', string.format('Unknown interaction mode %q ignored.\n', arg.interaction))
end
if build_bytecode then -- Effectivly if status.ini_version
require'luametalatex-lateinit'(build_bytecode)
else

View File

@ -16,9 +16,17 @@ require'luametalatex-font-resolve' -- Replace font.define. Must be loaded before
require'luametalatex-basecallbacks'
local callbacks = require'luametalatex-callbacks'
local function swap_table(t)
local s = {}
for k, v in next, t do
s[v] = k
end
return s
end
local primitives = {}
do
local token_primitives = token.primitives()
local token_primitives = token.getprimitives()
local token_new = token.new
for i=1,#token_primitives do
local prim = token_primitives[i]
@ -27,6 +35,12 @@ do
end
token.primitive_tokens = primitives
do
local command_id = swap_table(token.getcommandvalues())
function token.command_id(name) return command_id[name] end
end
token.value = swap_table(token.getfunctionvalues())
local functions = lua.getfunctionstable()
-- I am not sure why this is necessary, but otherwise LuaMetaTeX resets
-- the functions table every time the getter is called
@ -95,9 +109,9 @@ if initex then
for i=0,0 do -- maybeFIXME: In practise only one language is preloaded in LuaTeX anyway
-- for i=0,tex.count[19] do -- Sometimes catches reserved language ids which are not used yet
-- for i=0,lang.new():id()-1 do -- lang.new():id() is always 0 in luametatex?!?
local l = lang.new(i)
local l = language.new(i)
local str = string.format("do \z
local l = lang.new(%i)\z
local l = language.new(%i)\z
l:hyphenationmin(%i)\z
l:prehyphenchar(%i)\z
l:posthyphenchar(%i)\z

View File

@ -14,7 +14,7 @@ lua.get_functions_table()[restore_func] = function()
end
local restore_toks = {token.primitive_tokens.atendofgroup , token.new(restore_func, token.command_id'lua_call')}
local put_next = token.put_next
local runtoks = tex.runtoks
local runlocal = tex.runlocal
local function put_restore_toks()
put_next(restore_toks)
end
@ -35,7 +35,7 @@ return function(t, k, v, global)
local level = stack[l]
if not level then
level = {}
runtoks(put_restore_toks)
runlocal(put_restore_toks)
stack[l] = level
end

View File

@ -60,7 +60,7 @@ else
function geterrorcode(ec) return ec & 0xFF == 0 and ec >> 8 or 0xFF end
end
local firstargs = string.format("luametatex%s%s", late_arg_pattern:match('--lua=' .. file), late_arg_pattern:match('--arg0=' .. os.selfarg[0]))
local firstargs = string.format("luametatex --permitloadlib%s%s", late_arg_pattern:match('--lua=' .. file), late_arg_pattern:match('--arg0=' .. os.selfarg[0]))
local args = table.concat(os.selfarg)
if run then -- The user wants to take care of everything
os.exit(geterrorcode(os.execute(firstargs .. args)))