This commit is contained in:
Axel Kittenberger 2010-10-16 10:26:48 +00:00
parent a836a0bbfa
commit 75bcea5fde
2 changed files with 63 additions and 16 deletions

View File

@ -1,26 +1,70 @@
#include "config.h" #include "config.h"
#define LUA_USE_APICHECK 1
#ifdef HAVE_SYS_INOTIFY_H
# include <sys/inotify.h>
#else
# include "inotify-nosys.h"
#endif
#include <errno.h>
#include <stdio.h> #include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <lua.h> #include <lua.h>
#include <lualib.h> #include <lualib.h>
#include <lauxlib.h> #include <lauxlib.h>
/**
* The inotify file descriptor.
*/
static int inotify_fd;
/* the Lua interpreter */ /* the Lua interpreter */
lua_State* L; lua_State* L;
int main (int argc, char *argv[]) /**
{ * Adds a directory to be watched.
/* initialize Lua */ */
L = lua_open(); static int attend_dir (lua_State *L) {
/* load Lua base libraries */ //lua_pushnumber(L, sin(luaL_checknumber(L, 1)));
luaL_openlibs(L); printf("ATTEND_DIR\n");
/* register our function */ return 0;
/* lua_register(L, "average", average); */ }
/* run the script */
(void) luaL_dofile(L, "lsyncd.lua"); /**
/* cleanup Lua */ * The lsyncd-lua interface
lua_close(L); */
/* pause */ static const luaL_reg lsyncd_lib[] = {
printf( "Press enter to exit..." ); {"attend_dir", attend_dir},
getchar(); {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; return 0;
} }

View File

@ -1,2 +1,5 @@
print("Hello\n") print("Hello")
lsyncd:attend_dir()
print("Bye")