Initial commit
[project/iwinfo.git] / include / iwinfo / lua.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
28
29 #define IWINFO_META "iwinfo"
30 #define IWINFO_WEXT_META "iwinfo.wext"
31
32 #ifdef USE_WL
33 #define IWINFO_WL_META "iwinfo.wl"
34 #endif
35
36 #ifdef USE_MADWIFI
37 #define IWINFO_MADWIFI_META "iwinfo.madwifi"
38 #endif
39
40 #ifdef USE_NL80211
41 #define IWINFO_NL80211_META "iwinfo.nl80211"
42 #endif
43
44
45 #define LUA_REG(type,op) \
46 { #op, iwinfo_L_##type##_##op }
47
48 #define LUA_WRAP_INT_OP(type,op) \
49 static int iwinfo_L_##type##_##op(lua_State *L) \
50 { \
51 const char *ifname = luaL_checkstring(L, 1); \
52 int rv; \
53 if( !type##_ops.op(ifname, &rv) ) \
54 lua_pushnumber(L, rv); \
55 else \
56 lua_pushnil(L); \
57 return 1; \
58 }
59
60 #define LUA_WRAP_STRING_OP(type,op) \
61 static int iwinfo_L_##type##_##op(lua_State *L) \
62 { \
63 const char *ifname = luaL_checkstring(L, 1); \
64 char rv[IWINFO_BUFSIZE]; \
65 memset(rv, 0, IWINFO_BUFSIZE); \
66 if( !type##_ops.op(ifname, rv) ) \
67 lua_pushstring(L, rv); \
68 else \
69 lua_pushnil(L); \
70 return 1; \
71 }
72
73 #define LUA_WRAP_STRUCT_OP(type,op) \
74 static int iwinfo_L_##type##_##op(lua_State *L) \
75 { \
76 return iwinfo_L_##op(L, type##_ops.op); \
77 }
78
79 #endif