summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Pointner <equinox@helsinki.at>2015-07-26 18:41:44 (GMT)
committerChristian Pointner <equinox@helsinki.at>2015-07-26 18:41:44 (GMT)
commit7fd5f19cdde5e55775207ae95487b810785d1388 (patch)
tree3a4fda7f6b6069143859c384a6e95cb719c889ac /src
parent84d7a21071fa177657674596885c870c614d600b (diff)
some more lua5.2 fixes
added client remove handling fix from rhnop
Diffstat (limited to 'src')
-rw-r--r--src/luaclient.c29
-rw-r--r--src/mode-tcpserver.lua14
2 files changed, 33 insertions, 10 deletions
diff --git a/src/luaclient.c b/src/luaclient.c
index 7ac102d..104de52 100644
--- a/src/luaclient.c
+++ b/src/luaclient.c
@@ -43,7 +43,23 @@
#define LUA_MAIN_LOOP_FUNC "main_loop"
-static const luaL_Reg anylike_lualibs[] = {
+#if LUA_VERSION_NUM > 501
+static const luaL_Reg luaclient_lualibs[] = {
+ {"_G", luaopen_base},
+ {LUA_LOADLIBNAME, luaopen_package},
+ {LUA_TABLIBNAME, luaopen_table},
+ {LUA_STRLIBNAME, luaopen_string},
+ {LUA_MATHLIBNAME, luaopen_math},
+ {LUA_IOLIBNAME, luaopen_io},
+ {LUA_OSLIBNAME, luaopen_os},
+ {LUA_BITLIBNAME, luaopen_bit32},
+ {LUA_LOGLIBNAME, luaopen_log},
+ {LUA_SIGNALLIBNAME, luaopen_signal},
+ {LUA_CMDLIBNAME, luaopen_cmd},
+ {NULL, NULL}
+};
+#else
+static const luaL_Reg luaclient_lualibs[] = {
{"", luaopen_base},
{LUA_LOADLIBNAME, luaopen_package},
{LUA_TABLIBNAME, luaopen_table},
@@ -56,15 +72,24 @@ static const luaL_Reg anylike_lualibs[] = {
{LUA_CMDLIBNAME, luaopen_cmd},
{NULL, NULL}
};
+#endif
int init_main_loop(lua_State *L, const char* filename)
{
- const luaL_Reg *lib = anylike_lualibs;
+ const luaL_Reg *lib = luaclient_lualibs;
+
+#if LUA_VERSION_NUM > 501
+ for (; lib->func; lib++) {
+ luaL_requiref(L, lib->name, lib->func, 1);
+ lua_pop(L, 1);
+ }
+#else
for (; lib->func; lib++) {
lua_pushcfunction(L, lib->func);
lua_pushstring(L, lib->name);
lua_call(L, 1, 0);
}
+#endif
int ret = luaL_loadfile(L, filename);
if(ret) {
diff --git a/src/mode-tcpserver.lua b/src/mode-tcpserver.lua
index 78e416c..ced0f7d 100644
--- a/src/mode-tcpserver.lua
+++ b/src/mode-tcpserver.lua
@@ -52,18 +52,16 @@ function add_client(hdl)
end
function remove_client(c)
- local idx = 0
- local found = false
- for i, client in ipairs(clients) do
- if client == c then
- found = true
- idx = i
+ local idx = -1
+ for n, client in ipairs(clients) do
+ if client.getfd() == c.getfd() then
+ idx = n
break
end
end
- if found then
- log.printf(log.DEBUG, "removing client(" .. c.hdl:getfd() .. ")")
+ if idx > 0 then
+ log.printf(log.DEBUG, "removing client(" .. c.getfd() .. ")")
c.hdl:close()
table.remove(clients, idx)
end