Merge pull request #152 from devurandom/feature/simplify-register

Simplify register functions
This commit is contained in:
Axel Kittenberger 2012-10-01 21:42:12 -07:00
commit 604493029a
3 changed files with 19 additions and 19 deletions

View File

@ -351,8 +351,7 @@ inotify_ready(lua_State *L, struct observance *obs)
extern void extern void
register_inotify(lua_State *L) register_inotify(lua_State *L)
{ {
lua_pushstring(L, "inotify"); luaL_register(L, LSYNCD_INOTIFYLIBNAME, linotfylib);
luaL_register(L, "inotify", linotfylib);
} }
/** /**

View File

@ -1368,39 +1368,37 @@ l_jiffies_le(lua_State *L)
void void
register_lsyncd(lua_State *L) register_lsyncd(lua_State *L)
{ {
luaL_register(L, "lsyncd", lsyncdlib); luaL_register(L, LSYNCD_LIBNAME, lsyncdlib);
lua_setglobal(L, "lysncd"); lua_setglobal(L, LSYNCD_LIBNAME);
// creates the metatable for jiffies userdata // creates the metatable for jiffies userdata
luaL_newmetatable(L, "Lsyncd.jiffies"); luaL_newmetatable(L, "Lsyncd.jiffies");
lua_pushstring(L, "__add"); int mt = lua_gettop(L);
lua_pushcfunction(L, l_jiffies_add); 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_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_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_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_pushcfunction(L, l_jiffies_eq);
lua_settable(L, -3); lua_setfield(L, mt, "__eq");
lua_pop(L, 1);
lua_pop(L, 1); // pop(mt)
lua_getglobal(L, "lysncd");
#ifdef LSYNCD_WITH_INOTIFY #ifdef LSYNCD_WITH_INOTIFY
// TODO why is the here? lua_getglobal(L, LSYNCD_LIBNAME);
register_inotify(L); register_inotify(L);
lua_settable(L, -3); lua_setfield(L, -2, LSYNCD_INOTIFYLIBNAME);
#endif
lua_pop(L, 1); lua_pop(L, 1);
#endif
if (lua_gettop(L)) { if (lua_gettop(L)) {
logstring("Error", "internal, stack not empty in lsyncd_register()"); logstring("Error", "internal, stack not empty in lsyncd_register()");
exit(-1); // ERRNO exit(-1); // ERRNO

View File

@ -28,6 +28,9 @@
#define LUA_USE_APICHECK 1 #define LUA_USE_APICHECK 1
#include <lua.h> #include <lua.h>
#define LSYNCD_LIBNAME "lsyncd"
#define LSYNCD_INOTIFYLIBNAME "inotify"
/** /**
* Lsyncd runtime configuration * Lsyncd runtime configuration
*/ */