婷婷综合国产,91蜜桃婷婷狠狠久久综合9色 ,九九九九九精品,国产综合av

主頁 > 知識庫 > Lua之協同程序coroutine代碼實例

Lua之協同程序coroutine代碼實例

熱門標簽:冀州市地圖標注 個人怎么在地圖標注需要的店鋪 新岸線智能電銷機器人 百度地圖標注早餐區域 武漢外呼防封系統多少錢 地圖標注大廈 漳州智云呼電話機器人 怎么去除地圖標注 清朝地圖標注哈爾濱
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, 20



end

您可能感興趣的文章:
  • Lua協程(coroutine)程序運行分析
  • Lua的協程(coroutine)簡介
  • Lua協同程序(COROUTINE)運行步驟分解
  • Lua協同程序函數coroutine使用實例
  • Lua編程示例(七):協同程序基礎邏輯
  • 舉例詳解Lua中的協同程序編程
  • Lua中的協同程序詳解
  • Lua中的協同程序之resume-yield間的數據返回研究
  • Lua中的協同程序探究
  • Lua協同程序coroutine的簡介及優缺點

標簽:天門 宣城 儋州 金昌 天門 德宏 濰坊 臺灣

巨人網絡通訊聲明:本文標題《Lua之協同程序coroutine代碼實例》,本文關鍵詞  Lua,之,協同,程序,coroutine,;如發現本文內容存在版權問題,煩請提供相關信息告之我們,我們將及時溝通與處理。本站內容系統采集于網絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《Lua之協同程序coroutine代碼實例》相關的同類信息!
  • 本頁收集關于Lua之協同程序coroutine代碼實例的相關信息資訊供網民參考!
  • 推薦文章
    主站蜘蛛池模板: 青阳县| 工布江达县| 全椒县| 宁国市| 曲周县| 寻乌县| 鄄城县| 东阿县| 清丰县| 盘山县| 淳化县| 六安市| 汝城县| 栾城县| 邢台市| 建德市| 忻城县| 安吉县| 来凤县| 特克斯县| 通许县| 新乡市| 民县| 二手房| 鄂伦春自治旗| 古浪县| 宜州市| 封开县| 凤台县| 缙云县| 霸州市| 蕲春县| 鄱阳县| 金沙县| 奉新县| 丹江口市| 色达县| 屏山县| 贵阳市| 永川市| 将乐县|