Created
January 8, 2018 10:58
-
-
Save xiaobin83/11664856a5af1b0e4f29dff9915d6d24 to your computer and use it in GitHub Desktop.
lua delegate stub
This file contains hidden or 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
return function() | |
local methods = {} | |
local meta = { | |
__add = function(delegates, func) | |
methods[#methods + 1] = func | |
return delegates | |
end, | |
__sub = function(delegates, func) | |
for i, f in ipairs(methods) do | |
if f == func then | |
table.remove(methods, i) | |
end | |
end | |
return delegates | |
end, | |
__call = function(delegates, ...) | |
for _, f in ipairs(methods) do | |
f(...) | |
end | |
end | |
} | |
return setmetatable({}, meta) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment