libiwinfo: major changes
[project/luci.git] / contrib / package / iwinfo / src / include / iwinfo / lualib.h
1 /*
2  * iwinfo - Wireless Information Library - Lua Headers
3  *
4  *   Copyright (C) 2009 Jo-Philipp Wich <xm@subsignal.org>
5  *
6  * The iwinfo library is free software: you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License version 2
8  * as published by the Free Software Foundation.
9  *
10  * The iwinfo library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13  * See the GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with the iwinfo library. If not, see http://www.gnu.org/licenses/.
17  */
18
19 #ifndef __IWINFO_LUALUB_H_
20 #define __IWINFO_LUALIB_H_
21
22 #include <lua.h>
23 #include <lualib.h>
24 #include <lauxlib.h>
25
26 #include "iwinfo.h"
27 #include "iwinfo/wext_scan.h"
28
29
30 #define IWINFO_META                     "iwinfo"
31 #define IWINFO_WEXT_META        "iwinfo.wext"
32
33 #ifdef USE_WL
34 #define IWINFO_WL_META          "iwinfo.wl"
35 #endif
36
37 #ifdef USE_MADWIFI
38 #define IWINFO_MADWIFI_META     "iwinfo.madwifi"
39 #endif
40
41 #ifdef USE_NL80211
42 #define IWINFO_NL80211_META     "iwinfo.nl80211"
43 #endif
44
45
46 #define LUA_REG(type,op) \
47         { #op, iwinfo_L_##type##_##op }
48
49 #define LUA_WRAP_INT(type,op)                                                   \
50         static int iwinfo_L_##type##_##op(lua_State *L)         \
51         {                                                                                                       \
52                 const char *ifname = luaL_checkstring(L, 1);    \
53                 int rv;                                                                                 \
54                 if( !type##_get_##op(ifname, &rv) )                             \
55                         lua_pushnumber(L, rv);                                          \
56                 else                                                                                    \
57                         lua_pushnil(L);                                                         \
58                 return 1;                                                                               \
59         }
60
61 #define LUA_WRAP_STRING(type,op)                                                \
62         static int iwinfo_L_##type##_##op(lua_State *L)         \
63         {                                                                                                       \
64                 const char *ifname = luaL_checkstring(L, 1);    \
65                 char rv[IWINFO_BUFSIZE];                                                \
66                 memset(rv, 0, IWINFO_BUFSIZE);                                  \
67                 if( !type##_get_##op(ifname, rv) )                              \
68                         lua_pushstring(L, rv);                                          \
69                 else                                                                                    \
70                         lua_pushnil(L);                                                         \
71                 return 1;                                                                               \
72         }
73
74 #define LUA_WRAP_LIST(type,op)                                                  \
75         static int iwinfo_L_##type##_##op(lua_State *L)         \
76         {                                                                                                       \
77                 return iwinfo_L_##op(L, type##_get_##op);               \
78         }
79
80 #endif
81