Become compatible with LaTeX allocations
This commit is contained in:
parent
6c549049d1
commit
d72ac36935
@ -3,7 +3,6 @@ local newpdf = require'luametalatex-pdf'
|
|||||||
local pfile = newpdf.open(tex.jobname .. '.pdf')
|
local pfile = newpdf.open(tex.jobname .. '.pdf')
|
||||||
local fontdirs = setmetatable({}, {__index=function(t, k)t[k] = pfile:getobj() return t[k] end})
|
local fontdirs = setmetatable({}, {__index=function(t, k)t[k] = pfile:getobj() return t[k] end})
|
||||||
local usedglyphs = {}
|
local usedglyphs = {}
|
||||||
print(token, token.luacmd)
|
|
||||||
token.luacmd("shipout", function()
|
token.luacmd("shipout", function()
|
||||||
local voff = node.new'kern'
|
local voff = node.new'kern'
|
||||||
voff.kern = tex.voffset + tex.sp'1in'
|
voff.kern = tex.voffset + tex.sp'1in'
|
||||||
|
@ -4,10 +4,10 @@ local functions = lua.getfunctionstable()
|
|||||||
function lua.get_functions_table() return functions end
|
function lua.get_functions_table() return functions end
|
||||||
local set_lua = token.set_lua
|
local set_lua = token.set_lua
|
||||||
-- local new_luafunction = luatexbase.new_luafunction
|
-- local new_luafunction = luatexbase.new_luafunction
|
||||||
local i=12342
|
local predefined_luafunctions = 0
|
||||||
local function new_luafunction(name)
|
local function new_luafunction(name)
|
||||||
i = i+1
|
predefined_luafunctions = predefined_luafunctions + 1
|
||||||
return i
|
return predefined_luafunctions
|
||||||
end
|
end
|
||||||
function token.luacmd(name, func, ...)
|
function token.luacmd(name, func, ...)
|
||||||
local idx = new_luafunction(name)
|
local idx = new_luafunction(name)
|
||||||
@ -101,7 +101,7 @@ local function do_openout(p)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
functions[39] = function(_, immediate) -- \openout
|
token.luacmd("openout", function(_, immediate) -- \openout
|
||||||
local file = token.scan_int()
|
local file = token.scan_int()
|
||||||
token.scan_keyword'='
|
token.scan_keyword'='
|
||||||
local name = scan_filename()
|
local name = scan_filename()
|
||||||
@ -113,14 +113,14 @@ functions[39] = function(_, immediate) -- \openout
|
|||||||
properties[whatsit] = props
|
properties[whatsit] = props
|
||||||
node.write(whatsit)
|
node.write(whatsit)
|
||||||
end
|
end
|
||||||
end
|
end, "protected")
|
||||||
local function do_closeout(p)
|
local function do_closeout(p)
|
||||||
if ofiles[p.file] then
|
if ofiles[p.file] then
|
||||||
ofiles[p.file]:close()
|
ofiles[p.file]:close()
|
||||||
ofiles[p.file] = nil
|
ofiles[p.file] = nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
functions[40] = function(_, immediate) -- \closeout
|
token.luacmd("closeout", function(_, immediate) -- \closeout
|
||||||
local file = token.scan_int()
|
local file = token.scan_int()
|
||||||
local props = {file = file, handle = do_closeout}
|
local props = {file = file, handle = do_closeout}
|
||||||
if immediate == "immediate" then
|
if immediate == "immediate" then
|
||||||
@ -130,7 +130,7 @@ functions[40] = function(_, immediate) -- \closeout
|
|||||||
properties[whatsit] = props
|
properties[whatsit] = props
|
||||||
node.write(whatsit)
|
node.write(whatsit)
|
||||||
end
|
end
|
||||||
end
|
end, "protected")
|
||||||
local function do_write(p)
|
local function do_write(p)
|
||||||
local content = token.to_string(p.data) .. '\n'
|
local content = token.to_string(p.data) .. '\n'
|
||||||
local file = ofiles[p.file]
|
local file = ofiles[p.file]
|
||||||
@ -140,7 +140,7 @@ local function do_write(p)
|
|||||||
texio.write_nl(p.file < 0 and "log" or "term and log", content)
|
texio.write_nl(p.file < 0 and "log" or "term and log", content)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
functions[41] = function(_, immediate) -- \write
|
token.luacmd("write", function(_, immediate) -- \write
|
||||||
local file = token.scan_int()
|
local file = token.scan_int()
|
||||||
local content = token.scan_tokenlist()
|
local content = token.scan_tokenlist()
|
||||||
local props = {file = file, data = content, handle = do_write}
|
local props = {file = file, data = content, handle = do_write}
|
||||||
@ -151,29 +151,31 @@ functions[41] = function(_, immediate) -- \write
|
|||||||
properties[whatsit] = props
|
properties[whatsit] = props
|
||||||
node.write(whatsit)
|
node.write(whatsit)
|
||||||
end
|
end
|
||||||
end
|
end, "protected")
|
||||||
local lua_call_cmd = token.command_id'lua_call'
|
local lua_call_cmd = token.command_id'lua_call'
|
||||||
functions[42] = function() -- \immediate
|
token.luacmd("immediate", function() -- \immediate
|
||||||
local next_tok = token.scan_token()
|
local next_tok = token.scan_token()
|
||||||
if next_tok.command ~= lua_call_cmd then
|
if next_tok.command ~= lua_call_cmd then
|
||||||
return token.put_next(next_tok)
|
return token.put_next(next_tok)
|
||||||
end
|
end
|
||||||
local function_id = next_tok.index
|
local function_id = next_tok.index
|
||||||
functions[function_id](function_id, 'immediate')
|
functions[function_id](function_id, 'immediate')
|
||||||
end
|
end, "protected")
|
||||||
functions[43] = function() -- \pdfvariable
|
-- functions[43] = function() -- \pdfvariable
|
||||||
local name = token.scan_string()
|
-- local name = token.scan_string()
|
||||||
print('Missing \\pdf' .. name)
|
-- print('Missing \\pdf' .. name)
|
||||||
end
|
-- end
|
||||||
token.set_lua("openout", 39, "protected")
|
|
||||||
token.set_lua("closeout", 40, "protected")
|
|
||||||
token.set_lua("write", 41, "protected")
|
|
||||||
write_tok = token.create'write'
|
|
||||||
token.set_lua("immediate", 42, "protected")
|
|
||||||
token.set_lua("pdfvariable", 43)
|
|
||||||
local prepared_code = lua.bytecode[1]
|
local prepared_code = lua.bytecode[1]
|
||||||
if prepared_code then
|
if prepared_code then
|
||||||
prepared_code()
|
prepared_code()
|
||||||
prepared_code, lua.bytecode[1] = nil, nil
|
prepared_code, lua.bytecode[1] = nil, nil
|
||||||
|
function fixupluafunctions()
|
||||||
|
new_luafunction = luatexbase.new_luafunction
|
||||||
|
fixupluafunctions = nil
|
||||||
|
end
|
||||||
|
else
|
||||||
|
function fixupluafunctions()
|
||||||
|
tex.setcount("global", "e@alloc@luafunction@count", predefined_luafunctions)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
require'luametalatex-back-pdf'
|
require'luametalatex-back-pdf'
|
||||||
|
@ -30,5 +30,8 @@
|
|||||||
\input luametalatex-baseregisters
|
\input luametalatex-baseregisters
|
||||||
\let\dump\savedversionofdump
|
\let\dump\savedversionofdump
|
||||||
\let\savedversionofdump\undefined
|
\let\savedversionofdump\undefined
|
||||||
|
\directlua{fixupluafunctions()}%
|
||||||
|
\everyjob\expandafter{\the\everyjob\directlua{fixupluafunctions()}}%
|
||||||
|
\directlua{fixupluafunctions()}%
|
||||||
\dump
|
\dump
|
||||||
\endinput
|
\endinput
|
||||||
|
Loading…
Reference in New Issue
Block a user