Skip to content

Instantly share code, notes, and snippets.

@xiaobin83
Created January 8, 2018 10:58
Show Gist options
  • Save xiaobin83/11664856a5af1b0e4f29dff9915d6d24 to your computer and use it in GitHub Desktop.
Save xiaobin83/11664856a5af1b0e4f29dff9915d6d24 to your computer and use it in GitHub Desktop.
lua delegate stub
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