print("Lua 协程测试2")
function testFun(n)
print("into foo,n = "..n)
return coroutine.yield( * n) -- 挂起co协程
end
co = coroutine.create( -- 创建co协程
function(a,b)
print("into co 1,a = "..a..",b = "..b)
local r = testFun(a)
print("into co 2,r = "..r..",a = "..a..",b = "..b)
local m,n = coroutine.yield( * a , * b) -- 挂起co协程
print("into co 3,m = "..m..",n = "..n..",a = "..a..",b = "..b)
return a,b,"结束co协程"
end
)
print("main",coroutine.resume(co,,)) -- 启动co协程
print("main",coroutine.resume(co,"resume1")) -- 唤醒co协程
print("main",coroutine.resume(co,"resume2-m","resume2-n")) -- 唤醒co协程
print("main",coroutine.status(co))
运行结果:
Lua 协程测试2
into co ,a = ,b =
into foo,n =
main true
into co ,r = resume1,a = ,b =
main true
into co ,m = resume2-m,n = resume2-n,a = ,b =
main true 结束co协程
main dead