diff --git a/inotify.c b/inotify.c index dbb1335..fcbcef0 100644 --- a/inotify.c +++ b/inotify.c @@ -351,8 +351,7 @@ inotify_ready(lua_State *L, struct observance *obs) extern void register_inotify(lua_State *L) { - lua_pushstring(L, "inotify"); - luaL_register(L, "inotify", linotfylib); + luaL_register(L, LSYNCD_INOTIFYLIBNAME, linotfylib); } /** diff --git a/lsyncd.c b/lsyncd.c index 5433fd7..44a4a5d 100644 --- a/lsyncd.c +++ b/lsyncd.c @@ -1368,39 +1368,37 @@ l_jiffies_le(lua_State *L) void register_lsyncd(lua_State *L) { - luaL_register(L, "lsyncd", lsyncdlib); - lua_setglobal(L, "lysncd"); + luaL_register(L, LSYNCD_LIBNAME, lsyncdlib); + lua_setglobal(L, LSYNCD_LIBNAME); // 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) - lua_getglobal(L, "lysncd"); #ifdef LSYNCD_WITH_INOTIFY - // TODO why is the here? + lua_getglobal(L, LSYNCD_LIBNAME); register_inotify(L); - lua_settable(L, -3); -#endif + lua_setfield(L, -2, LSYNCD_INOTIFYLIBNAME); lua_pop(L, 1); +#endif + if (lua_gettop(L)) { logstring("Error", "internal, stack not empty in lsyncd_register()"); exit(-1); // ERRNO 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 */