【通过栈进行交互】
栈顶
2 -1
1 -2
栈底
int down_users(lua_State *L) {
char *pIp = NULL;
char *pMac = NULL;
int objLen = lua_objlen(L, 1);
int i = 0;
/* 遍历数组 */
for (i = 0; i < objLen; i++) {
lua_rawgeti(L, 1, i + 1);
/* 获取IP */
lua_pushliteral(L, "ip");
lua_rawget(L, -2);
pIp = lua_tostring(L, -1);
/* 获取MAC */
lua_pushliteral(L, "mac");
lua_rawget(L, -3);
pMac = lua_tostring(L, -1);
printf("%d ip<%s> mac<%s>\n", i, pIp, pMac);
lua_pop(L, 3);
}
return 1;
}