aboutsummaryrefslogtreecommitdiff
path: root/vis-lua.c
diff options
context:
space:
mode:
authorMarc André Tanner <mat@brain-dump.org>2020-12-29 15:56:03 +0100
committerMarc André Tanner <mat@brain-dump.org>2020-12-29 15:56:03 +0100
commit85f1bef9e867f38b4f8817b04417106567afe2ad (patch)
treea94a64a5d8d2f5832cec63c54a4d1e0e01ce580f /vis-lua.c
parentadf65e1dca8d3c0381133be8446eebddf412d772 (diff)
downloadvis-85f1bef9e867f38b4f8817b04417106567afe2ad.tar.gz
vis-85f1bef9e867f38b4f8817b04417106567afe2ad.tar.xz
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
Diffstat (limited to 'vis-lua.c')
-rw-r--r--vis-lua.c10
1 files changed, 10 insertions, 0 deletions
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);