From 3d065fccba86f7622f15ca1e89f22bca558b27c9 Mon Sep 17 00:00:00 2001 From: Dennis Schridde Date: Mon, 1 Oct 2012 19:45:21 +0200 Subject: [PATCH 1/4] Fix typo in name of Lua global table lysncd->lsyncd --- lsyncd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lsyncd.c b/lsyncd.c index 5433fd7..fa7813c 100644 --- a/lsyncd.c +++ b/lsyncd.c @@ -1369,7 +1369,7 @@ void register_lsyncd(lua_State *L) { luaL_register(L, "lsyncd", lsyncdlib); - lua_setglobal(L, "lysncd"); + lua_setglobal(L, "lsyncd"); // creates the metatable for jiffies userdata luaL_newmetatable(L, "Lsyncd.jiffies"); @@ -1394,7 +1394,7 @@ register_lsyncd(lua_State *L) lua_settable(L, -3); lua_pop(L, 1); - lua_getglobal(L, "lysncd"); + lua_getglobal(L, "lsyncd"); #ifdef LSYNCD_WITH_INOTIFY // TODO why is the here? register_inotify(L); From 702f6d3d4ea172df0506e898b470b32b41340bde Mon Sep 17 00:00:00 2001 From: Dennis Schridde Date: Mon, 1 Oct 2012 22:54:52 +0200 Subject: [PATCH 2/4] Make register_inotify() a bit more obvious --- inotify.c | 1 - lsyncd.c | 8 ++++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/inotify.c b/inotify.c index dbb1335..0d3916c 100644 --- a/inotify.c +++ b/inotify.c @@ -351,7 +351,6 @@ inotify_ready(lua_State *L, struct observance *obs) extern void register_inotify(lua_State *L) { - lua_pushstring(L, "inotify"); luaL_register(L, "inotify", linotfylib); } diff --git a/lsyncd.c b/lsyncd.c index fa7813c..c0deb5a 100644 --- a/lsyncd.c +++ b/lsyncd.c @@ -1394,13 +1394,13 @@ register_lsyncd(lua_State *L) lua_settable(L, -3); lua_pop(L, 1); - lua_getglobal(L, "lsyncd"); #ifdef LSYNCD_WITH_INOTIFY - // TODO why is the here? + lua_getglobal(L, "lsyncd"); register_inotify(L); - lua_settable(L, -3); -#endif + lua_setfield(L, -2, "inotify"); lua_pop(L, 1); +#endif + if (lua_gettop(L)) { logstring("Error", "internal, stack not empty in lsyncd_register()"); exit(-1); // ERRNO From 68982e6e5b98406673d3da2d3cc7764c4e737ef0 Mon Sep 17 00:00:00 2001 From: Dennis Schridde Date: Mon, 1 Oct 2012 22:58:25 +0200 Subject: [PATCH 3/4] Simplify register_lsyncd(), too --- lsyncd.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/lsyncd.c b/lsyncd.c index c0deb5a..b2c9d47 100644 --- a/lsyncd.c +++ b/lsyncd.c @@ -1373,26 +1373,24 @@ register_lsyncd(lua_State *L) // creates the metatable for jiffies userdata luaL_newmetatable(L, "Lsyncd.jiffies"); - lua_pushstring(L, "__add"); + int mt = lua_gettop(L); + lua_pushcfunction(L, l_jiffies_add); - lua_settable(L, -3); + lua_setfield(L, mt, "__add"); - lua_pushstring(L, "__sub"); lua_pushcfunction(L, l_jiffies_sub); - lua_settable(L, -3); + lua_setfield(L, mt, "__sub"); - lua_pushstring(L, "__lt"); lua_pushcfunction(L, l_jiffies_lt); - lua_settable(L, -3); + lua_setfield(L, mt, "__lt"); - lua_pushstring(L, "__le"); lua_pushcfunction(L, l_jiffies_le); - lua_settable(L, -3); + lua_setfield(L, mt, "__le"); - lua_pushstring(L, "__eq"); lua_pushcfunction(L, l_jiffies_eq); - lua_settable(L, -3); - lua_pop(L, 1); + lua_setfield(L, mt, "__eq"); + + lua_pop(L, 1); // pop(mt) #ifdef LSYNCD_WITH_INOTIFY lua_getglobal(L, "lsyncd"); From dea7e87b4044142a6210c157a6d4ea00e60d29eb Mon Sep 17 00:00:00 2001 From: Dennis Schridde Date: Tue, 2 Oct 2012 02:56:29 +0200 Subject: [PATCH 4/4] Use LSYNCD_*LIBNAME to refer to lsyncd/.inotify tables This should prevent typos and resulting issues --- inotify.c | 2 +- lsyncd.c | 8 ++++---- lsyncd.h | 3 +++ 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/inotify.c b/inotify.c index 0d3916c..fcbcef0 100644 --- a/inotify.c +++ b/inotify.c @@ -351,7 +351,7 @@ inotify_ready(lua_State *L, struct observance *obs) extern void register_inotify(lua_State *L) { - luaL_register(L, "inotify", linotfylib); + luaL_register(L, LSYNCD_INOTIFYLIBNAME, linotfylib); } /** diff --git a/lsyncd.c b/lsyncd.c index b2c9d47..44a4a5d 100644 --- a/lsyncd.c +++ b/lsyncd.c @@ -1368,8 +1368,8 @@ l_jiffies_le(lua_State *L) void register_lsyncd(lua_State *L) { - luaL_register(L, "lsyncd", lsyncdlib); - lua_setglobal(L, "lsyncd"); + luaL_register(L, LSYNCD_LIBNAME, lsyncdlib); + lua_setglobal(L, LSYNCD_LIBNAME); // creates the metatable for jiffies userdata luaL_newmetatable(L, "Lsyncd.jiffies"); @@ -1393,9 +1393,9 @@ register_lsyncd(lua_State *L) lua_pop(L, 1); // pop(mt) #ifdef LSYNCD_WITH_INOTIFY - lua_getglobal(L, "lsyncd"); + lua_getglobal(L, LSYNCD_LIBNAME); register_inotify(L); - lua_setfield(L, -2, "inotify"); + lua_setfield(L, -2, LSYNCD_INOTIFYLIBNAME); lua_pop(L, 1); #endif diff --git a/lsyncd.h b/lsyncd.h index 88ef323..fa598a7 100644 --- a/lsyncd.h +++ b/lsyncd.h @@ -28,6 +28,9 @@ #define LUA_USE_APICHECK 1 #include +#define LSYNCD_LIBNAME "lsyncd" +#define LSYNCD_INOTIFYLIBNAME "inotify" + /** * Lsyncd runtime configuration */