wrap和Create差不多,都是去創(chuàng)建一個coroutine,有些區(qū)別:
1,wrap不會通過resume去得到第一個返回值(錯誤信息)
2,在創(chuàng)建完之后,直接調(diào)用函數(shù),轉(zhuǎn)到coroutine,而create卻要resume才能轉(zhuǎn)到coroutine。
3,wrap不能查看狀態(tài)。
例子代碼:
復(fù)制代碼 代碼如下:
do
function createWrap()
return coroutine.wrap(function(x)
print("Hello", x);
coroutine.yield();
print("continue")
end);
end
coA = createWrap(); --get the function, resum the coroutine
coA(3);
coA(3); --call the global function, , resum the coroutine
end