[luatex] luatexbase.add_to_callback does not preserve the order
David Carlisle
d.p.carlisle at gmail.com
Wed Feb 3 11:12:26 CET 2016
I put a comment in github but I think that this fixes the issue (using
ipairs rather than pairs in add_to_callback so the list is constituted
in the right order) Below I redefine add_to_callback in the test file
but if you locally edit luatexbase.sty with that definition and could
confirm it works on your original files, we will push an update to
ctan, thanks again.
\batchmode
\input luatexbase.sty
\directlua{
function luatexbase.add_to_callback(name,fun,description,priority)
local priority= priority
local len=\string#luatexbase.callback_descriptions(name)
if (priority==nil) then
priority=len+1
end
if(luatexbase.callbacktypes[name] == 3 and
priority == 1 and
len==1) then
luatexbase.module_warning("luatexbase",
"resetting exclusive callback: " .. name)
luatexbase.reset_callback(name)
end
local saved_callback={},ff,dd
for k,v in ipairs(luatexbase.callback_descriptions(name)) do
if k >= priority then
ff,dd= luatexbase.remove_from_callback(name, v)
saved_callback[1+k-priority]={ff,dd}
end
end
luatexbase.base_add_to_callback(name,fun,description)
for k,v in ipairs(saved_callback) do
luatexbase.base_add_to_callback(name,v[1],v[2])
end
return
end
}
\scrollmode\catcode`\_=12
\directlua{
luatexbase.create_callback('test', 'data', function(n) return n end)
local fn = {}
for n=1,20 do
fn[n] = function()
texio.write(tostring(n) .. ', '); return 1
end
luatexbase.add_to_callback('test', fn[n], n, n)
end
luatexbase.call_callback('test', 0)
texio.write_nl('')
for i=1,300 do
local n = math.random(20)
luatexbase.remove_from_callback('test', n) % remove fn[n]
luatexbase.add_to_callback('test', fn[n], n, n)
end
texio.write_nl('')
luatexbase.call_callback('test', 0)
}
\batchmode\bye
More information about the luatex
mailing list