fun = function() print(123) end print("**************携程的创建****************") -- (1)coroutine.create() -- (2)coroutine.wrap() co = coroutine.create( fun ) co2= coroutine.wrap( fun ) print(co2) print(type(co2)) print("**************携程的运行****************") -- (1) 对应的create 创建的携程, 返回一个 boolean -- (2) co() print(coroutine.resume(co)) co2() print("**************携程的挂起****************") -- (1)coroutine.yield -- (2) coroutine.create(fun) 之后resume:返回true 和 yiled 值 -- (3) coroutine.wrap(co) 没有boolean返回值 但是可以yield返回值 fun2 = function() local i = 1 while true do print(i) i = i + 1 coroutine.yield() end end co3 = coroutine.create(fun2) coroutine.resume(co3) coroutine.resume(co3) coroutine.resume(co3) temp = coroutine.resume(co3) print("**************携程的状态***************") -- coroutine.status(协程对象) -- dead -- suspended -- running print(coroutine.status( co3 )) print(coroutine.status(co)) print(coroutine.running( ))