Skip to content
This repository was archived by the owner on Nov 20, 2020. It is now read-only.

Commit de5b388

Browse files
committed
Merge pull request keplerproject#1 from Tieske/nil_params
Bugfix; properly pack/unpack nil parameters
2 parents 2044bcb + b69fe1a commit de5b388

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/coxpcall.lua

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
-- yielding inside the call to pcall or xpcall.
77
--
88
-- Authors: Roberto Ierusalimschy and Andre Carregal
9-
-- Contributors: Thomas Harning Jr., Ignacio Burgueño, Fábio Mascarenhas
9+
-- Contributors: Thomas Harning Jr., Ignacio Burgueño, Fabio Mascarenhas
1010
--
1111
-- Copyright 2005 - Kepler Project (www.keplerproject.org)
1212
--
@@ -25,7 +25,9 @@ end
2525
-------------------------------------------------------------------------------
2626
local performResume, handleReturnValue
2727
local oldpcall, oldxpcall = pcall, xpcall
28-
28+
local pack = table.pack or function(...) return {n = select("#", ...), ...} end
29+
local unpack = table.unpack or unpack
30+
2931
function handleReturnValue(err, co, status, ...)
3032
if not status then
3133
return false, err(debug.traceback(co, (...)), ...)
@@ -44,8 +46,8 @@ end
4446
function coxpcall(f, err, ...)
4547
local res, co = oldpcall(coroutine.create, f)
4648
if not res then
47-
local params = {...}
48-
local newf = function() return f(unpack(params)) end
49+
local params = pack(...)
50+
local newf = function() return f(unpack(params, 1, params.n)) end
4951
co = coroutine.create(newf)
5052
end
5153
return performResume(err, co, ...)

0 commit comments

Comments
 (0)