I am learning Lua coroutines. I found a tied thing for me, both
meta = function () for i = 1, 10 do coroutine.yield(i) end end for i in coroutine.wrap(function() return meta() end) do print(i) end
and
meta = function () for i = 1, 10 do coroutine.yield(i) end end for i in coroutine.wrap(function() meta() end) do print(i) end
(note that there is a refund in the first version) give me
~ / test% lua t.lua
1
2
3
4
5
6
7
eight
nine
ten
So what is the role of return ? I think meta() will return a value, and an anonymous function will also return it. So why is an anonymous function without return also correct?
source share