libs/iwinfo: unify LUA_WRAP_ASSOCLIST and LUA_WRAP_TXPWRLIST macros
authorJo-Philipp Wich <jow@openwrt.org>
Wed, 19 Aug 2009 20:52:46 +0000 (20:52 +0000)
committerJo-Philipp Wich <jow@openwrt.org>
Wed, 19 Aug 2009 20:52:46 +0000 (20:52 +0000)
libs/iwinfo/src/iwinfo_lualib.c
libs/iwinfo/src/iwinfo_lualib.h

index 6974280b74ff5a740f893f7d2b43809d1190137f..e63eeabd4d9e2bf8e6a5827812bea746823dc785 100644 (file)
@@ -92,7 +92,6 @@ static int iwinfo_L_txpwrlist(lua_State *L, int (*func)(const char *, char *, in
                {
                        e = (struct iwinfo_txpwrlist_entry *) &rv[i];
 
-                       lua_pushinteger(L, x);
                        lua_newtable(L);
 
                        lua_pushnumber(L, e->mw);
@@ -101,7 +100,7 @@ static int iwinfo_L_txpwrlist(lua_State *L, int (*func)(const char *, char *, in
                        lua_pushnumber(L, e->dbm);
                        lua_setfield(L, -2, "dbm");
 
-                       lua_settable(L, -3);
+                       lua_rawseti(L, -2, x);
                }
        }
 
@@ -121,8 +120,8 @@ LUA_WRAP_STRING(wl,mode)
 LUA_WRAP_STRING(wl,ssid)
 LUA_WRAP_STRING(wl,bssid)
 LUA_WRAP_STRING(wl,enctype)
-LUA_WRAP_ASSOCLIST(wl)
-LUA_WRAP_TXPWRLIST(wl)
+LUA_WRAP_LIST(wl,assoclist)
+LUA_WRAP_LIST(wl,txpwrlist)
 
 /* Madwifi */
 LUA_WRAP_INT(madwifi,channel)
@@ -137,8 +136,8 @@ LUA_WRAP_STRING(madwifi,mode)
 LUA_WRAP_STRING(madwifi,ssid)
 LUA_WRAP_STRING(madwifi,bssid)
 LUA_WRAP_STRING(madwifi,enctype)
-LUA_WRAP_ASSOCLIST(madwifi)
-LUA_WRAP_TXPWRLIST(madwifi)
+LUA_WRAP_LIST(madwifi,assoclist)
+LUA_WRAP_LIST(madwifi,txpwrlist)
 
 /* Wext */
 LUA_WRAP_INT(wext,channel)
@@ -153,8 +152,8 @@ LUA_WRAP_STRING(wext,mode)
 LUA_WRAP_STRING(wext,ssid)
 LUA_WRAP_STRING(wext,bssid)
 LUA_WRAP_STRING(wext,enctype)
-LUA_WRAP_ASSOCLIST(wext)
-LUA_WRAP_TXPWRLIST(wext)
+LUA_WRAP_LIST(wext,assoclist)
+LUA_WRAP_LIST(wext,txpwrlist)
 
 /* Broadcom table */
 static const luaL_reg R_wl[] = {
index 909080bb45ad7d8990bcb9ee8daa82c1349c2daa..f7eba149d1e020a2e203d2cc84b9e7ef0ec6accb 100644 (file)
                return 1;                                                                               \
        }
 
-#define LUA_WRAP_ASSOCLIST(type)                                               \
-       static int iwinfo_L_##type##_assoclist(lua_State *L)\
-       {                                                                                                       \
-               return iwinfo_L_assoclist(L,                                    \
-                       type##_get_assoclist);                                          \
-       }
-
-#define LUA_WRAP_TXPWRLIST(type)                                               \
-       static int iwinfo_L_##type##_txpwrlist(lua_State *L)\
+#define LUA_WRAP_LIST(type,op)                                                 \
+       static int iwinfo_L_##type##_##op(lua_State *L)         \
        {                                                                                                       \
-               return iwinfo_L_txpwrlist(L,                                    \
-                       type##_get_txpwrlist);                                          \
+               return iwinfo_L_##op(L, type##_get_##op);               \
        }
 
 #endif