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"
#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 <string.h>
#include <unistd.h>
#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>
/**
* 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;
}

View File

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