fix permissions to allow users to execute install-wmiirc-lua script
[wmiirc-lua.git] / luaeventloop / lel_main.c
blob1b2bbbd081b23d562f7a2cd61c1a8c83462d743d
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <unistd.h>
4 #include <string.h>
5 #include <errno.h>
6 #include <time.h>
7 #include <signal.h>
9 #include <lua.h>
10 #include <lauxlib.h>
12 #include "lel_debug.h"
13 #include "lel_util.h"
14 #include "lel_instance.h"
17 /* ------------------------------------------------------------------------
18 * lua: x = eventloop.new() -- create a new eventloop object
20 static int l_new (lua_State *L)
22 struct lel_eventloop *el;
24 DBGF("** eventloop.new () **\n");
26 el = (struct lel_eventloop*)lua_newuserdata(L, sizeof (struct lel_eventloop));
28 luaL_getmetatable (L, L_EVENTLOOP_MT);
29 lua_setmetatable (L, -2);
31 memset (el, 0, sizeof(*el));
32 FD_ZERO (&el->all_fds);
34 return 1;
37 static int l_eventloop_gc (lua_State *L)
39 struct lel_eventloop *el;
41 el = lel_checkeventloop (L, 1);
43 DBGF("** eventloop:__gc (%p) **\n", el);
45 return 0;
48 /* ------------------------------------------------------------------------
49 * the class method table
51 static const luaL_reg class_table[] =
53 { "new", l_new },
55 { NULL, NULL },
58 /* ------------------------------------------------------------------------
59 * the instance method table
61 static const luaL_reg instance_table[] =
63 { "__tostring", l_eventloop_tostring },
64 { "__gc", l_eventloop_gc },
66 { "add_exec", l_eventloop_add_exec },
67 { "kill_exec", l_eventloop_kill_exec },
69 { "run_loop", l_eventloop_run_loop },
71 { "kill_all", l_eventloop_kill_all },
73 { NULL, NULL },
76 /* ------------------------------------------------------------------------
77 * the class metatable
79 static int lel_init_eventloop_class (lua_State *L)
81 luaL_newmetatable(L, L_EVENTLOOP_MT);
83 // setup the __index and __gc field
84 lua_pushstring (L, "__index");
85 lua_pushvalue (L, -2); // pushes the new metatable
86 lua_settable (L, -3); // metatable.__index = metatable
88 luaL_openlib (L, NULL, instance_table, 0);
89 luaL_openlib (L, "eventloop", class_table, 0);
91 #if 0
92 luaL_register (L, MYNAME, R);
93 lua_pushliteral (L, "version");
94 lua_pushliteral (L, MYVERSION);
95 lua_settable (L, -3);
96 #endif
97 return 1;
100 /* ------------------------------------------------------------------------
101 * library entry
103 LUALIB_API int luaopen_eventloop (lua_State *L)
105 return lel_init_eventloop_class (L);