From 85f1bef9e867f38b4f8817b04417106567afe2ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Andr=C3=A9=20Tanner?= Date: Tue, 29 Dec 2020 15:56:03 +0100 Subject: vis-lua: provide file.permission property These are the permission bits of struct stat's st_mode field at the time of the most recent load/save. Close #861 --- vis-lua.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'vis-lua.c') diff --git a/vis-lua.c b/vis-lua.c index f3bd7d0..0642343 100644 --- a/vis-lua.c +++ b/vis-lua.c @@ -2097,6 +2097,10 @@ static const struct luaL_Reg window_selection_funcs[] = { * File state. * @tfield bool modified whether the file contains unsaved changes */ +/*** + * File permission. + * @tfield int permission the file permission bits as of the most recent load/save + */ static int file_index(lua_State *L) { File *file = obj_ref_check(L, 1, VIS_LUA_TYPE_FILE); @@ -2126,6 +2130,12 @@ static int file_index(lua_State *L) { lua_pushboolean(L, text_modified(file->text)); return 1; } + + if (strcmp(key, "permission") == 0) { + struct stat stat = text_stat(file->text); + lua_pushunsigned(L, stat.st_mode & 0777); + return 1; + } } return index_common(L); -- cgit v1.2.3