[luatex] multiple callbacks

Hans Hagen pragma at wxs.nl
Sun Jan 4 16:32:51 CET 2009


Taco Hoekwater wrote:

> That is exactly what Elie said. He wrote: "a small lua function", not
> "a small extension to the core".

untested, but something like this can do the job (untested)

local list = {}

function callback.add(name,func,priority)
     list[name] = list[name] or { }
     if not priority then
         table.insert(list[name],func)
     elseif priority < 1 then
         table.insert(list[name],func,1)
     elseif priority > list[name] then
         table.insert(list[name],func)
     else
         table.insert(list[name],func,priority)
     end
end

function callback.listhandler(name)
     return function(head,...)
         for _, func in ipairs(list[name]) do
             head = func(head,...)
         end
         return head, true
     end
end

callback.register("whatever",callback.listhandler("whatever"))

of course there remains the dilemma of two style writers wanting a high 
priority

Hans

-----------------------------------------------------------------
                                           Hans Hagen | PRAGMA ADE
               Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
      tel: 038 477 53 69 | fax: 038 477 53 74 | www.pragma-ade.com
                                              | www.pragma-pod.nl
-----------------------------------------------------------------


More information about the luatex mailing list