Merge pull request #809 from lite-xl/merge-master-2.0

Merge master 2.0
This commit is contained in:
Adam
2022-01-28 14:38:22 -05:00
committed by GitHub
11 changed files with 704 additions and 177 deletions
+55 -5
View File
@@ -560,6 +560,14 @@ static int f_get_file_info(lua_State *L) {
}
lua_setfield(L, -2, "type");
#if __linux__
if (S_ISDIR(s.st_mode)) {
if (lstat(path, &s) == 0) {
lua_pushboolean(L, S_ISLNK(s.st_mode));
lua_setfield(L, -2, "symlink");
}
}
#endif
return 1;
}
@@ -600,6 +608,11 @@ static int f_get_fs_type(lua_State *L) {
lua_pushstring(L, "unknown");
return 1;
}
#else
static int f_return_unknown(lua_State *L) {
lua_pushstring(L, "unknown");
return 1;
}
#endif
@@ -794,20 +807,47 @@ static int f_load_native_plugin(lua_State *L) {
static int f_watch_dir(lua_State *L) {
const char *path = luaL_checkstring(L, 1);
const int recursive = lua_toboolean(L, 2);
uint32_t dmon_flags = (recursive ? DMON_WATCHFLAGS_RECURSIVE : 0);
dmon_watch_id watch_id = dmon_watch(path, dirmonitor_watch_callback, dmon_flags, NULL);
if (watch_id.id == 0) { luaL_error(L, "directory monitoring watch failed"); }
/* On linux we watch non-recursively and we add/remove each sub-directory explicitly
* using the function system.watch_dir_add/rm. On other systems we watch recursively
* and system.watch_dir_add/rm are dummy functions that always returns true. */
#if __linux__
const uint32_t dmon_flags = DMON_WATCHFLAGS_FOLLOW_SYMLINKS;
#elif __APPLE__
const uint32_t dmon_flags = DMON_WATCHFLAGS_FOLLOW_SYMLINKS | DMON_WATCHFLAGS_RECURSIVE;
#else
const uint32_t dmon_flags = DMON_WATCHFLAGS_RECURSIVE;
#endif
dmon_error error;
dmon_watch_id watch_id = dmon_watch(path, dirmonitor_watch_callback, dmon_flags, NULL, &error);
if (watch_id.id == 0) {
lua_pushnil(L);
lua_pushstring(L, dmon_error_str(error));
return 2;
}
lua_pushinteger(L, watch_id.id);
return 1;
}
static int f_unwatch_dir(lua_State *L) {
dmon_watch_id watch_id;
watch_id.id = luaL_checkinteger(L, 1);
dmon_unwatch(watch_id);
return 0;
}
#if __linux__
static int f_watch_dir_add(lua_State *L) {
dmon_watch_id watch_id;
watch_id.id = luaL_checkinteger(L, 1);
const char *subdir = luaL_checkstring(L, 2);
lua_pushboolean(L, dmon_watch_add(watch_id, subdir));
dmon_error error_code;
int success = dmon_watch_add(watch_id, subdir, &error_code);
if (!success) {
lua_pushboolean(L, 0);
lua_pushstring(L, dmon_error_str(error_code));
return 2;
}
lua_pushboolean(L, 1);
return 1;
}
@@ -818,6 +858,11 @@ static int f_watch_dir_rm(lua_State *L) {
lua_pushboolean(L, dmon_watch_rm(watch_id, subdir));
return 1;
}
#else
static int f_return_true(lua_State *L) {
lua_pushboolean(L, 1);
return 1;
}
#endif
#ifdef _WIN32
@@ -906,11 +951,16 @@ static const luaL_Reg lib[] = {
{ "set_window_opacity", f_set_window_opacity },
{ "load_native_plugin", f_load_native_plugin },
{ "watch_dir", f_watch_dir },
{ "unwatch_dir", f_unwatch_dir },
{ "path_compare", f_path_compare },
#if __linux__
{ "watch_dir_add", f_watch_dir_add },
{ "watch_dir_rm", f_watch_dir_rm },
{ "get_fs_type", f_get_fs_type },
#else
{ "watch_dir_add", f_return_true },
{ "watch_dir_rm", f_return_true },
{ "get_fs_type", f_return_unknown },
#endif
{ NULL, NULL }
};