summaryrefslogtreecommitdiff
path: root/testes/coroutine.lua
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2019-05-09 11:13:45 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2019-05-09 11:13:45 -0300
commit389116d8abcc96db3cfe2f3cc25789c089fe12d6 (patch)
treef3d07b50c17f28ba09cf547d5a67519ffe3271a4 /testes/coroutine.lua
parent01bded3d8cd88a2d7f472b45f706565f1a9ef3b1 (diff)
downloadlua-github-389116d8abcc96db3cfe2f3cc25789c089fe12d6.tar.gz
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.
Diffstat (limited to 'testes/coroutine.lua')
-rw-r--r--testes/coroutine.lua8
1 files changed, 6 insertions, 2 deletions
diff --git a/testes/coroutine.lua b/testes/coroutine.lua
index 35ff27fb..9dd501e7 100644
--- a/testes/coroutine.lua
+++ b/testes/coroutine.lua
@@ -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