Skip to content

Instantly share code, notes, and snippets.

@Rottweiler
Created September 11, 2017 21:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Rottweiler/c0b4d2c756d3e047e21e202d951bee10 to your computer and use it in GitHub Desktop.
Save Rottweiler/c0b4d2c756d3e047e21e202d951bee10 to your computer and use it in GitHub Desktop.
detour
detour = detour or {}
local detours = detour.detours or {}
detour.detours = detours
function detour.AddDetour(tbl, key, func)
detours[tbl] = detours[tbl] or {}
local original = tbl[key]
detours[tbl][key] = detours[tbl][key] or {
original = original,
func = func
}
tbl[key] = function(...)
return func(original, ...)
end
end
function detour.GetDetour(tbl, key)
return detours[tbl] and detours[tbl][key]
end
function detour.IsDetoured(tbl, key)
return detour.GetDetour(tbl,key) and true or false
end
function detour.RemoveDetour(tbl, key)
if (detours[tbl]) then
local detour = detours[tbl][key]
tbl[key] = detour.original
detours[tbl][key] = nil
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment