aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc André Tanner <mat@brain-dump.org>2016-09-19 14:20:28 +0200
committerMarc André Tanner <mat@brain-dump.org>2016-09-19 14:20:28 +0200
commit478b86451c7896b5dc7f18962975a42549686b8e (patch)
tree4226a5f7c98b7929471ce22efc8616869e460064
parentcea4400702eb0eeba57598540388d98a5104cb2d (diff)
downloadvis-478b86451c7896b5dc7f18962975a42549686b8e.tar.gz
vis-478b86451c7896b5dc7f18962975a42549686b8e.tar.xz
vis-lua: expose file open event to lua
The event is only triggerred for new files read from disk (e.g. splitting an existing window will not cause an event to be emitted).
-rw-r--r--README.md1
-rw-r--r--vis-lua.c7
2 files changed, 8 insertions, 0 deletions
diff --git a/README.md b/README.md
index c88f5f7..284b80b 100644
--- a/README.md
+++ b/README.md
@@ -585,6 +585,7 @@ At this time there exists no API stability guarantees.
- `events` hooks
- `start()`
- `quit()`
+ - `file_open(file)`
- `win_open(win)`
- `win_close(win)`
- `theme_change(name)`
diff --git a/vis-lua.c b/vis-lua.c
index 56949fe..91ce414 100644
--- a/vis-lua.c
+++ b/vis-lua.c
@@ -1503,6 +1503,13 @@ void vis_lua_quit(Vis *vis) {
void vis_lua_file_open(Vis *vis, File *file) {
debug("event: file-open: %s %p %p\n", file->name ? file->name : "unnamed", (void*)file, (void*)file->text);
+ lua_State *L = vis->lua;
+ vis_lua_event_get(L, "file_open");
+ if (lua_isfunction(L, -1)) {
+ obj_ref_new(L, file, "vis.file");
+ pcall(vis, L, 1, 0);
+ }
+ lua_pop(L, 1);
}
void vis_lua_file_save(Vis *vis, File *file) {