Skip to content

Instantly share code, notes, and snippets.

@creationix
Created August 7, 2012 18:32
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 creationix/94d8bd5e815dcbfa98fe to your computer and use it in GitHub Desktop.
Save creationix/94d8bd5e815dcbfa98fe to your computer and use it in GitHub Desktop.
function utils.bind(fn, self, ...)
local argsLength = select("#", ...)
if argsLength == 0 then
return function (...)
return fn(self, ...)
end
else
-- This table will get mutated on every call, but it's async safe and the
-- unpack fence will only use the fresh data so it's ok.
local args = {...}
return function (...)
local extraLength = select("#", ...)
local extra = {...}
for i = 1, extraLength do
args[i + argsLength] = extra[i]
end
return fn(self, unpack(args, 1, argsLength + extraLength))
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment