-- Add a hookfunction add_hook(object, name, fn, priority) local h = {name = name, fn = fn, priority = priority} object.hooks = object.hooks or {} local n = #object.hooks + 1 for i, v in ipairs(object.hooks) do if v.priority <= priority then n = i break end end table.insert(object.hooks, n, h);end-- Remove hooks by namefunction remove_hooks(object, name) if object.hooks then for i, v in ipairs(object.hooks) do if v.name == name then table.remove(object.hooks, i) end end endend-- Remove a hook by referencefunction remove_hook(object, hook) if object.hooks then for i, v in ipairs(object.hooks) do if v == hook then table.remove(object.hooks, i) end end endend-- Run hooks by namefunction run_hooks(object, name, params) for i, v in ipairs(object.hooks) do if (v.name == name) then v.fn(object, params) if params.quit then break end end endend