国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > 綜合 > 正文

Lua之協同程序coroutine代碼實例

2024-07-21 23:04:34
字體:
來源:轉載
供稿:網友
do	--create coroutine table	--coroutine state: suspended, running, dead, normal	--when create the coroutine, the status is suspended, After calling it, the status is dead	--get the coroutine status by the way coroutine.status	local coA = 0;	local coB = 0;	function createCoroutineA()		coA = coroutine.create(										function()											--for i = 0, 10 do												print("coA: ", 0);												print("coB status: ", coroutine.status(coB)); --normal status												print("coA status: ", coroutine.status(coA));												print("coA coroutine next status");												--coroutine.yield();--the current coroutine is suspended											--end										end									);		print("From coA to resume coB");	end	function createCoroutineB()		coB = coroutine.create(										function()											--for i = 0, 10 do												print("coB: ", 0);												print("coA status: ", coroutine.status(coA));												coroutine.resume(coA); --when resume coA, the coB will suspended, calling coB ,the coA status is												--suspended and dead, this time will continue to execute the next code												print("coB status: ", coroutine.status(coB));												print("coB coroutine next status");												--coroutine.yield();											--end										end									);		print("From coB to resume coA");	end	--display the coA and coB status	createCoroutineA();	print(coroutine.status(coA));	createCoroutineB();	print(coroutine.status(coB));	coroutine.resume(coB);	print(coroutine.resume(coB)); --if the coroutine is dead ,the resume will resume false, and can't resume the dead coroutine	--print("coA status: ", coroutine.status(coA));	--print("coB status: ", coroutine.status(coB));end

注:
resume得到返回值,
如果有對應的yield在wait resume,那么yield的參數作為resum的返回值,第一個返回值表示coroutine沒有錯誤,后面的返回值個數及其值視yeild參數而定。
如果沒有yield在wait,那么返回值是對應函數的返回值,:true,* * *

do	--create coroutine table	--coroutine state: suspended, running, dead, normal	--when create the coroutine, the status is suspended, After calling it, the status is dead	--get the coroutine status by the way coroutine.status	local coA = 0;	local coB = 0;	function createCoroutineA()		coA = coroutine.create(										function(paramA, paramB)											--for i = 0, 10 do												print("coA: ", 0);												coroutine.yield(paramA, paramB);--the current coroutine is suspended											--end											return 100, 200;										end									);		print("From coA to resume coB");	end	function createCoroutineB()		coB = coroutine.create(										function()											--for i = 0, 10 do												print("coB: ", 0);												print("coA status: ", coroutine.status(coA));												coroutine.resume(coA); --when resume coA, the coB will suspended, calling coB ,the coA status is												--suspended and dead, this time will continue to execute the next code												print("coB status: ", coroutine.status(coB));												print("coB coroutine next status");												--coroutine.yield();											--end										end									);		print("From coB to resume coA");	end	createCoroutineA();	--if not yield is waiting ,the return values that the main function return as the results of the resume	--or the return as the yield params	print( coroutine.resume(coA, 10, 20));--OutPut:true, 10, 20end

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 武平县| 新安县| 正蓝旗| 博乐市| 湖北省| 镇赉县| 义乌市| 故城县| 安新县| 永顺县| 宁晋县| 光山县| 贡觉县| 疏勒县| 营山县| 惠东县| 凌云县| 鸡泽县| 板桥市| 同德县| 墨脱县| 黄冈市| 昌图县| 芮城县| 廊坊市| 怀宁县| 尼玛县| 铜鼓县| 宿松县| 保康县| 香格里拉县| 宜宾市| 宕昌县| 黑龙江省| 綦江县| 拜城县| 平武县| 油尖旺区| 亳州市| 浦江县| 濮阳市|