wrap和Create差不多,都是去創建一個coroutine,有些區別:
1,wrap不會通過resume去得到第一個返回值(錯誤信息)
2,在創建完之后,直接調用函數,轉到coroutine,而create卻要resume才能轉到coroutine。
3,wrap不能查看狀態。
例子代碼:
復制代碼 代碼如下:
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