国产探花免费观看_亚洲丰满少妇自慰呻吟_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

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 巴马| 晋宁县| 施甸县| 凤山市| 东乌| 红桥区| 正宁县| 邵武市| 汾西县| 阳西县| 泾源县| 阳新县| 阿图什市| 岱山县| 民丰县| 保亭| 赞皇县| 洪雅县| 马山县| 江津市| 寿光市| 扎鲁特旗| 黔西| 右玉县| 汉寿县| 永济市| 灵石县| 宿迁市| 绵竹市| 云南省| 浏阳市| 兰溪市| 西乌| 米林县| 遂溪县| 安图县| 城固县| 中牟县| 宜宾市| 田林县| 什邡市|