[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: coxpcall invocation question
- From: "Thomas Harning Jr." <harningt@...>
- Date: Fri, 21 Aug 2009 12:25:38 -0400
Looking through the coxpcall code, I noticed something that seemed a little odd:
function coxpcall(f, err, ...)
local res, co = oldpcall(coroutine.create, f)
if not res then
local params = {...}
local newf = function() return f(unpack(params)) end
co = coroutine.create(newf)
end
return performResume(err, co, ...)
end
If tries to create a coroutine and if that fails, constructs a new
function that unpacks args/etc to get things going.
I presume this is to support calling objects that implement the __call
metatable that coroutine.create may not handle...
A short fix to remove unpacking would be this... since performResume
already passes new args in:
if not res then
local newf = function(...) return f(...) end
co = coroutine.create(newf)
end
I suspect this may have been left in from when I made patches before
since I hadn't quite understood all the vararg handling then.
If that fix doesn't work... then the pack/unpack will need to capture
the # of args to make sure nil args are passed in....
Fix:
if not res then
local params = {n = select('#', ...), ...}
local newf = function() return f(unpack(params, 1, n)) end
co = coroutine.create(newf)
end
--
Thomas Harning Jr.