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);//清空栈
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章