1. 【通过栈进行交互】
    2. 栈顶
    3. 2 -1
    4. 1 -2
    5. 栈底
    6. int down_users(lua_State *L) {
    7. char *pIp = NULL;
    8. char *pMac = NULL;
    9. int objLen = lua_objlen(L, 1);
    10. int i = 0;
    11. /* 遍历数组 */
    12. for (i = 0; i < objLen; i++) {
    13. lua_rawgeti(L, 1, i + 1);
    14. /* 获取IP */
    15. lua_pushliteral(L, "ip");
    16. lua_rawget(L, -2);
    17. pIp = lua_tostring(L, -1);
    18. /* 获取MAC */
    19. lua_pushliteral(L, "mac");
    20. lua_rawget(L, -3);
    21. pMac = lua_tostring(L, -1);
    22. printf("%d ip<%s> mac<%s>\n", i, pIp, pMac);
    23. lua_pop(L, 3);
    24. }
    25. return 1;
    26. }