'coroutine.close'/'lua_resetthread' report original errors

Besides errors in closing methods, 'coroutine.close' and
'lua_resetthread' also consider the original error that stopped the
thread, if any.
This commit is contained in:
Roberto Ierusalimschy
2020-12-18 11:22:42 -03:00
parent b17178b27a
commit 409256b784
5 changed files with 40 additions and 15 deletions

View File

@@ -135,14 +135,18 @@ if T then
local topB, sizeB -- top and size Before overflow
local topA, sizeA -- top and size After overflow
topB, sizeB = T.stacklevel()
collectgarbage("stop") -- __gc should not be called with a full stack
xpcall(f, err)
collectgarbage("restart")
topA, sizeA = T.stacklevel()
-- sizes should be comparable
assert(topA == topB and sizeA < sizeB * 2)
print(string.format("maximum stack size: %d", stack1))
LIM = N -- will stop recursion at maximum level
N = 0 -- to count again
collectgarbage("stop") -- __gc should not be called with a full stack
f()
collectgarbage("restart")
print"+"
end