luametalatex/luametalatex-callbacks.lua

25 lines
744 B
Lua
Raw Normal View History

2020-07-15 04:51:59 +02:00
-- Now overwrite the callback functionality. Our system is based on the ssumption there there are
-- no unknown callback names, just callbacks very unlikely to ever be called. That doesn't lead to
-- good error checking, but we expect this to be overwritten by LaTeX anyway.
local callback_find = callback.find
2020-07-15 16:36:11 +02:00
local callback_register = callback.register
2020-07-15 04:51:59 +02:00
local rawset = rawset
local callbacks = setmetatable({}, {
__index = function(cbs, name)
return callback_find(name)
end,
__newindex = function(cbs, name, new)
return callback_register(name, new) or rawset(cbs, name, new)
end,
})
function callback.register(name, new)
callbacks[name] = new
end
function callback.find(name)
return callbacks[name]
end
return callbacks