diff --git a/lsyncd.c b/lsyncd.c index 2bd7df7..5c28a28 100644 --- a/lsyncd.c +++ b/lsyncd.c @@ -1,26 +1,70 @@ #include "config.h" +#define LUA_USE_APICHECK 1 + +#ifdef HAVE_SYS_INOTIFY_H +# include +#else +# include "inotify-nosys.h" +#endif + +#include #include +#include +#include + #include #include #include +/** + * The inotify file descriptor. + */ +static int inotify_fd; + + /* the Lua interpreter */ lua_State* L; -int main (int argc, char *argv[]) -{ - /* initialize Lua */ - L = lua_open(); - /* load Lua base libraries */ - luaL_openlibs(L); - /* register our function */ - /* lua_register(L, "average", average); */ - /* run the script */ - (void) luaL_dofile(L, "lsyncd.lua"); - /* cleanup Lua */ - lua_close(L); - /* pause */ - printf( "Press enter to exit..." ); - getchar(); +/** + * Adds a directory to be watched. + */ +static int attend_dir (lua_State *L) { + //lua_pushnumber(L, sin(luaL_checknumber(L, 1))); + printf("ATTEND_DIR\n"); + return 0; +} + +/** + * The lsyncd-lua interface + */ +static const luaL_reg lsyncd_lib[] = { + {"attend_dir", attend_dir}, + {NULL, NULL}, +}; + + +int main (int argc, char *argv[]) +{ + /* load Lua */ + L = lua_open(); + luaL_openlibs(L); + luaL_register(L, "lsyncd", lsyncd_lib); + + luaL_loadfile(L, "lsyncd.lua"); + if (lua_pcall(L, 0, LUA_MULTRET, 0)) { + printf("error loading lsyncd.lua: %s\n", lua_tostring(L, -1)); + return -1; // ERRNO + } + + /* open inotify */ + inotify_fd = inotify_init(); + if (inotify_fd == -1) { + printf("Cannot create inotify instance! (%d:%s)", + errno, strerror(errno)); + return -1; // ERRNO + } + + close(inotify_fd); + lua_close(L); return 0; } diff --git a/lsyncd.lua b/lsyncd.lua index c1cc42b..db52c6b 100644 --- a/lsyncd.lua +++ b/lsyncd.lua @@ -1,2 +1,5 @@ -print("Hello\n") +print("Hello") +lsyncd:attend_dir() +print("Bye") +