0 K simple_handler_default() end local handlers = { [data] = data_handler, [exclusive] = exclusive_handler, [list] = list_handler, [reverselist] = reverselist_handler, [simple] = simple_handler, } local defaults = { [data] = data_handler_default, [exclusive] = nil, [list] = list_handler_default, [reverselist] = list_handler_default, [simple] = simple_handler_default, } local user_callbacks_defaults = {} local function create_callback(name, ctype, default) local ctype_id = types[ctype] if not name or name == "" or not ctype_id then luatexbase_error("Unable to create callback:\n" .. "valid callback name and type required") end if callbacktypes[name] then luatexbase_error("Unable to create callback `" .. name .. "':\ncallback is already defined") end default = default or defaults[ctype_id] if not default then luatexbase_error("Unable to create callback `" .. name .. "':\ndefault is required for `" .. ctype .. "' callbacks") elseif type (default) ~= "function" then luatexbase_error("Unable to create callback `" .. name .. "':\ndefault is not a function") end user_callbacks_defaults[name] = default callbacktypes[name] = ctype_id end luatexbase.create_callback = create_callback local function call_callback(name,...) if not name or name == "" then luatexbase_error("Unable to create callback:\n" .. "valid callback name required") end if user_callbacks_defaults[name] == nil then luatexbase_error("Unable to call callback `" .. name .. "':\nunknown or empty") end local l = callbacklist[name] local f if not l then f = user_callbacks_defaults[name] else f = handlers[callbacktypes[name]](name) end return f(...) end luatexbase.call_callback=call_callback local function add_to_callback(name, func, description) if not name or name == "" then luatexbase_error("Unable to register callback:\n" .. "valid callback name required") end if not callbacktypes[name] or type(func) ~= "function" or not description or description == "" then luatexbase_error( "Unable to register callback.\n\n" .. "Correct usage:\n" .. "add_to_callback(, , )" ) end local l = realcallbacklist[name] if l == nil then l = { } realcallbacklist[name] = l local shared = shared_callbacks[name] if shared then shared.count = shared.count + 1 if shared.count == 1 then callback_register(shared.callback, shared.handler) end elseif user_callbacks_defaults[name] == nil then callback_register(name, handlers[callbacktypes[name]](name)) end end local f = { func = func, description = description, } if callbacktypes[name] == exclusive then if #l == 1 then luatexbase_error( "Cannot add second callback to exclusive function\n`" .. name .. "'") end end table.insert(l, f) callbacklist[name] = nil luatexbase_log( "Inserting `" .. description .. "' in `" .. name .. "'." ) end luatexbase.add_to_callback = add_to_callback local function declare_callback_rule(name, desc1, relation, desc2) if not callbacktypes[name] or not desc1 or not desc2 or desc1 == "" or desc2 == "" then luatexbase_error( "Unable to create ordering constraint. " .. "Correct usage:\n" .. "declare_callback_rule(, , )" ) end if relation == 'before' then relation = nil elseif relation == 'after' then desc2, desc1 = desc1, desc2 relation = nil elseif relation == 'incompatible-warning' or relation == 'incompatible-error' then elseif relation == 'unrelated' then else luatexbase_error( "Unknown relation type in declare_callback_rule" ) end callbacklist[name] = nil local rules = callbackrule