Created
September 11, 2017 21:11
-
-
Save Rottweiler/c0b4d2c756d3e047e21e202d951bee10 to your computer and use it in GitHub Desktop.
detour
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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