Import luanet library
[project/luci.git] / libs / luanet / src / main.c
1 /*
2 * Licensed under the Apache License, Version 2.0 (the "License");
3 * you may not use this file except in compliance with the License.
4 * You may obtain a copy of the License at
5 *
6 * http://www.apache.org/licenses/LICENSE-2.0
7 *
8 * Unless required by applicable law or agreed to in writing, software
9 * distributed under the License is distributed on an "AS IS" BASIS,
10 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 * See the License for the specific language governing permissions and
12 * limitations under the License.
13 *
14 * Copyright (C) 2008 John Crispin <blogic@openwrt.org>
15 * Copyright (C) 2008 Steven Barth <steven@midlink.org>
16 */
17
18 #include <stdio.h>
19 #include <unistd.h>
20
21 #include <lua.h>
22 #include <lualib.h>
23 #include <lauxlib.h>
24
25 #include "route.h"
26 #include "bridge.h"
27 #include "ifconfig.h"
28 #include "iwconfig.h"
29 #include "vconfig.h"
30 #include "df.h"
31 #include "base64.h"
32
33 int psleep(lua_State *L)
34 {
35 int s;
36 if(lua_gettop(L) != 1)
37 {
38 lua_pushstring(L, "invalid arg list");
39 lua_error(L);
40 return 0;
41 }
42
43 s = (int)lua_tointeger (L, 1);
44 sleep(s);
45 return 0;
46 }
47
48 static luaL_reg func[] = {
49 {"ifc_getall", ifc_getall},
50 {"ifc_setip", ifc_setip},
51 {"ifc_setnetmask", ifc_setnetmask},
52 {"ifc_setbroadcast", ifc_setbroadcast},
53 {"ifc_setmtu", ifc_setmtu},
54 {"ifc_up", ifc_up},
55 {"ifc_down", ifc_down},
56 {"bridge_getall", bridge_getall},
57 {"bridge_new", bridge_new},
58 {"bridge_del", bridge_del},
59 {"bridge_addif", bridge_addif},
60 {"bridge_delif", bridge_delif},
61 {"iwc_getall", iwc_getall},
62 {"iwc_set_essid", iwc_set_essid},
63 {"iwc_set_mode", iwc_set_mode},
64 {"iwc_set_channel", iwc_set_channel},
65 {"iwc_scan", iwc_scan},
66 {"vlan_getall", vlan_getall},
67 {"vlan_add", vlan_add},
68 {"vlan_del", vlan_del},
69 {"df", df},
70 {"b64_encode", b64_encode},
71 {"b64_decode", b64_decode},
72 {"sleep", psleep},
73 {NULL, NULL}
74 };
75
76 int luaopen_luanet(lua_State *L)
77 {
78 ifc_startup();
79 bridge_startup();
80 iwc_startup();
81 luaL_openlib(L, "luanet", func, 0);
82 lua_pushstring(L, "_VERSION");
83 lua_pushstring(L, "1.0");
84 lua_rawset(L, -3);
85 return 1;
86 }
87
88 int luaclose_luanet(lua_State *L)
89 {
90 ifc_shutdown();
91 bridge_shutdown();
92 iwc_shutdown();
93 lua_pushstring(L, "Called");
94 return 1;
95 }