[luatex] luatexbase.add_to_callback does not preserve the order

Hironori KITAGAWA h_kitagawa2001 at yahoo.co.jp
Wed Feb 3 07:02:12 CET 2016


Hello, 

I typeset the following source:
======
\batchmode
\input luatexbase.sty
\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('')
  math.randomseed( os.time() )
  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
  luatexbase.call_callback('test', 0)
}

\batchmode\bye
======

and I got the following output:
======
This is LuaTeX, Version beta-0.81.1 (TeX Live 2016/dev) (rev 5460) 
 restricted \write18 enabled.
(./ltb_callback.tex
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 14, 19, 15, 13, 17, 18, 20, 16, 
======
(The luatex binary is compiled by myself, and I used
 luatexbase.sty 2015/10/04 v1.3.)

The latter half of the source (after 'math.randomseed(...)') does
removing & reinserting a function from a callback. So, I think that
the 2 lines in the output should be identical, but not so.

Regards 
Hironori KITAGAWA <h_kitagawa2001 at yahoo.co.jp>


More information about the luatex mailing list