2019-07-17 21:14:34 +02:00
|
|
|
do
|
2020-07-10 20:46:08 +02:00
|
|
|
local ourpath
|
|
|
|
ourpath, texconfig.formatname = lua.startupfile:match('(.*[/\\])([^/\\]*)%-init%.lua$')
|
2020-07-13 20:31:37 +02:00
|
|
|
local function try_lib(name)
|
|
|
|
local path = string.format('%s%s.%s', ourpath, name,
|
|
|
|
os.type == 'windows' and 'dll' or 'so')
|
|
|
|
return package.loadlib(path, '*') and path
|
|
|
|
end
|
|
|
|
local library = try_lib'luametalatex' or try_lib'kpse'
|
|
|
|
if not library then
|
|
|
|
error[[C support library not found. Please fix your installation]]
|
|
|
|
end
|
|
|
|
kpse = assert(package.loadlib(library, 'luaopen_luametalatex_kpse') or package.loadlib(library, 'luaopen_kpse'))()
|
|
|
|
package.loaded.kpse = kpse
|
|
|
|
package.preload.luaharfbuzz = package.loadlib(library, 'luaopen_luametalatex_harfbuzz') or package.loadlib(library, 'luaopen_luametalatex_harfbuzz') or nil
|
2019-07-17 21:14:34 +02:00
|
|
|
end
|
2019-07-18 20:02:58 +02:00
|
|
|
do
|
2020-07-10 20:46:08 +02:00
|
|
|
local arg_pattern = '-' * lpeg.P'-'^-1 * lpeg.C((1-lpeg.P'=')^1) * ('=' * lpeg.C(lpeg.P(1)^0) + lpeg.Cc(true))
|
2020-05-26 19:29:58 +02:00
|
|
|
for _, a in ipairs(arg) do
|
2020-07-10 20:46:08 +02:00
|
|
|
local name, value = arg_pattern:match(a)
|
|
|
|
if name then
|
2020-07-17 03:59:44 +02:00
|
|
|
arg[name] = math.tointeger(value) or value
|
2020-05-26 19:29:58 +02:00
|
|
|
end
|
|
|
|
end
|
2019-07-18 20:02:58 +02:00
|
|
|
end
|
2020-07-10 20:46:08 +02:00
|
|
|
kpse.set_program_name(arg.arg0 or arg[arg[0]], arg.progname)
|
2021-03-20 19:00:02 +01:00
|
|
|
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
|
2019-07-17 21:14:34 +02:00
|
|
|
package.searchers[2] = function(modname)
|
2020-05-26 19:29:58 +02:00
|
|
|
local filename = kpse.find_file(modname, "lua", true)
|
2019-07-17 21:14:34 +02:00
|
|
|
if not filename then
|
|
|
|
return string.format("\n\tno file located through kpse for %s", modname)
|
|
|
|
end
|
|
|
|
local mod, msg = loadfile(filename)
|
|
|
|
if msg then
|
|
|
|
error(string.format("error loading module '%s' from file '%s':\n\t%s", modname, filename, msg))
|
|
|
|
end
|
|
|
|
return mod, filename
|
|
|
|
end
|
2020-07-05 15:42:27 +02:00
|
|
|
kpse.set_maketex("fmt", true, "compile")
|
2020-07-05 20:40:09 +02:00
|
|
|
kpse.set_maketex("pk", true, "compile")
|
2019-07-20 16:39:34 +02:00
|
|
|
require'luametalatex-init-config'
|
2020-06-11 01:16:42 +02:00
|
|
|
local callback_register = callback.register
|
2020-07-04 06:27:30 +02:00
|
|
|
local build_bytecode
|
2021-03-20 19:00:02 +01:00
|
|
|
status.ini_version = status.run_state == 0
|
2020-07-04 06:27:30 +02:00
|
|
|
if status.ini_version then
|
|
|
|
local build_bytecode_mod = require'luametalatex-build-bytecode'
|
|
|
|
local preloaded_modules = {}
|
|
|
|
local old_searcher = package.searchers[2]
|
|
|
|
package.searchers[2] = function(name)
|
|
|
|
local mod, file = old_searcher(name)
|
|
|
|
if not file then return mod end -- Only works because we always return file when successful
|
|
|
|
preloaded_modules[#preloaded_modules+1] = {name, file}
|
|
|
|
return mod, file
|
2020-06-11 01:16:42 +02:00
|
|
|
end
|
2020-07-04 06:27:30 +02:00
|
|
|
function build_bytecode(str)
|
|
|
|
return load(build_bytecode_mod(preloaded_modules) .. "\nrequire'luametalatex-lateinit'(function()" .. str .. '\nend)', 'preloaded', 't')
|
2020-06-11 01:16:42 +02:00
|
|
|
end
|
|
|
|
end
|
2020-07-04 06:27:30 +02:00
|
|
|
|
2021-03-20 19:00:02 +01:00
|
|
|
callback_register('find_format_file', function(name) texconfig.formatname = kpse.find_file(name, 'fmt', true) return texconfig.formatname end)
|
|
|
|
-- texconfig.firstline = [[\show ]]
|
2020-05-26 19:29:58 +02:00
|
|
|
function texconfig.init()
|
2020-07-04 06:27:30 +02:00
|
|
|
if build_bytecode then -- Effectivly if status.ini_version
|
|
|
|
require'luametalatex-lateinit'(build_bytecode)
|
|
|
|
else
|
|
|
|
local register = tex.count[262]+1
|
|
|
|
lua.bytecode[register]()
|
|
|
|
lua.bytecode[register] = nil
|
2020-05-26 19:29:58 +02:00
|
|
|
end
|
2019-07-17 21:14:34 +02:00
|
|
|
end
|