Lua练习21-lua的协程

2020-10-16  本文已影响0人  GameObjectLgy
co2 = coroutine.create(
    function()
        for i=1,10 do
            print(i)
            if i == 3 then
                print(coroutine.status(co2))  --running
                print(coroutine.running()) --thread:XXXXXX
            end
            coroutine.yield()
        end
    end
)
 
coroutine.resume(co2) --1
coroutine.resume(co2) --2
coroutine.resume(co2) --3
 
print(coroutine.status(co2))   -- suspended
print(coroutine.running())
 
print("----------")

结果:
1
2
3
running
thread: 000002D22CB860C8 false
suspended
thread: 000002D22CAC9428 true


上一篇下一篇

猜你喜欢

热点阅读