lsyncd/lsyncd.c

71 lines
1.2 KiB
C
Raw Normal View History

2010-10-14 13:56:23 +00:00
#include "config.h"
2010-10-16 10:26:48 +00:00
#define LUA_USE_APICHECK 1
#ifdef HAVE_SYS_INOTIFY_H
# include <sys/inotify.h>
#else
# include "inotify-nosys.h"
#endif
#include <errno.h>
2010-10-14 13:52:01 +00:00
#include <stdio.h>
2010-10-16 10:26:48 +00:00
#include <string.h>
#include <unistd.h>
2010-10-14 13:52:01 +00:00
#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>
2010-10-16 10:26:48 +00:00
/**
* The inotify file descriptor.
*/
static int inotify_fd;
2010-10-14 13:52:01 +00:00
/* the Lua interpreter */
lua_State* L;
2010-10-16 10:26:48 +00:00
/**
* 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},
};
2010-10-14 13:52:01 +00:00
int main (int argc, char *argv[])
{
2010-10-16 10:26:48 +00:00
/* load Lua */
2010-10-14 13:52:01 +00:00
L = lua_open();
luaL_openlibs(L);
2010-10-16 10:26:48 +00:00
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);
2010-10-14 13:52:01 +00:00
lua_close(L);
return 0;
}