Coroutines do not unwind the stack in case of errors
Back to how it was, a coroutine does not unwind its stack in case of errors (and therefore do not close its to-be-closed variables). This allows the stack to be examined after the error. The program can use 'coroutine.kill' to close the variables. The function created by 'coroutine.wrap', however, closes the coroutine's variables in case of errors, as it is impossible to examine the stack any way.
This commit is contained in:
@@ -346,9 +346,13 @@ do
|
||||
local st, res = coroutine.resume(B)
|
||||
assert(st == true and res == false)
|
||||
|
||||
A = coroutine.wrap(function() return pcall(A, 1) end)
|
||||
local X = false
|
||||
A = coroutine.wrap(function()
|
||||
local *toclose _ = setmetatable({}, {__close = function () X = true end})
|
||||
return pcall(A, 1)
|
||||
end)
|
||||
st, res = A()
|
||||
assert(not st and string.find(res, "non%-suspended"))
|
||||
assert(not st and string.find(res, "non%-suspended") and X == true)
|
||||
end
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user