婷婷综合国产,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代碼實例的相關信息資訊供網民參考!
  • 推薦文章
    主站蜘蛛池模板: 安福县| 米泉市| 鄂尔多斯市| 江源县| 壤塘县| 将乐县| 兰考县| 娄底市| 冕宁县| 苍梧县| 乌兰县| 南阳市| 镇原县| 洛阳市| 鄢陵县| 枣庄市| 河池市| 普安县| 廉江市| 九寨沟县| 兴义市| 余干县| 辛集市| 夏河县| 卫辉市| 浦城县| 盐亭县| 太湖县| 阿拉善右旗| 张家港市| 仁化县| 比如县| 海城市| 长乐市| 荥经县| 搜索| 海原县| 吴桥县| 辽阳县| 民丰县| 宝兴县|