-
-
Save Castux/fb37b60ec853c690c8193c90b3510476 to your computer and use it in GitHub Desktop.
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
-- Original code | |
tpz = {} | |
tpz.testMethod = function(a, b, c) | |
print(a, b, c) | |
end | |
-- 'Module' helper | |
module = {} | |
module.override = function(t, name, func) | |
local old = t[name] | |
local thisenv = getfenv(old) | |
local env = { super = old } | |
setmetatable(env, { __index = thisenv }) | |
setfenv(func, env) | |
t[name] = func | |
end | |
-- Module content | |
module.override(tpz, 'testMethod', | |
function(a, b, c) | |
super(a,b,c) | |
print(a + 1, b + 1, c + 1) | |
end) | |
module.override(tpz, 'testMethod', | |
function(a,b,c) | |
print "play it again, sam" | |
super(a,b,c) | |
end) | |
-- Game runtime | |
tpz.testMethod(1, 2, 3) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment