Lua C API遍歷 多維table

*Lua 數據類型

table={
	{1,2,3},
	{"1","2","3"},
}

C API 遍歷table

lua_getglobal(L, t);//獲取lua table
lua_pushnil(L);//壓入nil 作爲KEY
while (lua_next(L, -2)) {//
	//多維table -1 table ,-2 key
	lua_pushnil(L);//壓入nil 作爲KEY
	while (lua_next(L, -2)) {//
		//內層數組
		/* 此時棧上 -1 處爲 value, -2 處爲 key */
		lua_tostring(-1);
		lua_pop(L, 1);//從棧中彈出 當前元素 讓 table 在棧頂
	}
    lua_pop(L, 1);//從棧中彈出 當前元素 讓 table 在棧頂
}
lua_pop(L, 1);//清空棧
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章