aboutsummaryrefslogtreecommitdiff
path: root/vis-lua.c
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fischer@muhq.space>2024-05-10 08:55:56 +0200
committerRandy Palamar <randy@rnpnr.xyz>2024-05-12 09:16:29 -0600
commit352ee0761ced17612d751bd568c888c78d279e9f (patch)
tree9db6cc3c62b5506144b96a7aa89f7c616470c269 /vis-lua.c
parent50a7673370fa037960e9d2c3a8d6aed1bb9c39c4 (diff)
downloadvis-352ee0761ced17612d751bd568c888c78d279e9f.tar.gz
vis-352ee0761ced17612d751bd568c888c78d279e9f.tar.xz
lua: allow changing the displayed file of a window
Change the file displayed in a window by writing the new file name to the window's file member. This is useful to change the displayed file during events. Using the edit command during an event caused by a pervious edit command causes a double free.
Diffstat (limited to 'vis-lua.c')
-rw-r--r--vis-lua.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/vis-lua.c b/vis-lua.c
index a62daf8..ca36d2d 100644
--- a/vis-lua.c
+++ b/vis-lua.c
@@ -2019,6 +2019,12 @@ static int window_newindex(lua_State *L) {
}
lua_pop(L, 1);
return ret;
+ } else if (strcmp(key, "file") == 0 && lua_isstring(L, 3)) {
+ const char* filename = lua_tostring(L, 3);
+ if (!vis_window_change_file(win, filename)) {
+ return luaL_argerror(L, 3, "failed to open");
+ }
+ return 0;
}
}