[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Lua 5.4 supports yield from __close, but fails with coroutine.close
- From: Jan Behrens <jbe-mlist@...>
- Date: Sun, 17 Sep 2023 12:55:35 +0200
Hello everyone,
according to this post
<http://lua-users.org/lists/lua-l/2022-06/msg00077.html> from Roberto
Ierusalimschy, Lua 5.4 should support "yield from __close". However, I
ran into problems when combining this with "coroutine.close".
Consider the following program:
===========
local function generate()
return coroutine.create(
function()
local guard <close> = setmetatable(
{},
{
__close = function()
coroutine.yield("B")
end,
}
)
coroutine.yield("A")
end
)
end
print("This works:")
local t1 = generate()
while coroutine.status(t1) ~= "dead" do
print(assert(coroutine.resume(t1)))
end
print("But this does not:")
local t2 = generate()
print(assert(coroutine.resume(t2)))
print(assert(coroutine.close(t2)))
===========
Running this with Lua 5.4.4, I get the following output:
===
This works:
true A
true B
true
But this does not:
true A
lua: cantyield.lua:28: attempt to yield across a C-call boundary
stack traceback:
[C]: in function 'assert'
cantyield.lua:28: in main chunk
[C]: in ?
===
Is this a bug that could/should be fixed?
Kind Regards,
Jan Behrens
Attachment:
cantyield.lua
Description: Binary data