aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc André Tanner <mat@brain-dump.org>2016-04-15 23:26:08 +0200
committerMarc André Tanner <mat@brain-dump.org>2016-04-16 12:52:04 +0200
commitf3d3af1e836cd2896f47a5a219e85c84f0022ed5 (patch)
tree1b854e6f51056f44bb4a994c88df4f2bd63a3f6b
parent7418386e7b0528b7d67847d84333e9f149dc8a58 (diff)
downloadvis-f3d3af1e836cd2896f47a5a219e85c84f0022ed5.tar.gz
vis-f3d3af1e836cd2896f47a5a219e85c84f0022ed5.tar.xz
vis-lua: add window.cursors_iterator function
-rw-r--r--README.md1
-rw-r--r--vis-lua.c24
2 files changed, 25 insertions, 0 deletions
diff --git a/README.md b/README.md
index 28c2704..d2538d0 100644
--- a/README.md
+++ b/README.md
@@ -598,6 +598,7 @@ At this time there exists no API stability guarantees.
- `window`
- `file`
- `syntax` lexer name used for syntax highlighting or `nil`
+ - `cursors_iterator()`
- `cursor` primary cursor
- `line` (1 based), `col` (1 based)
- `to(line, col)`
diff --git a/vis-lua.c b/vis-lua.c
index 5141cfa..5ba1865 100644
--- a/vis-lua.c
+++ b/vis-lua.c
@@ -551,9 +551,33 @@ static int window_newindex(lua_State *L) {
return newindex_common(L);
}
+static int window_cursors_iterator_next(lua_State *L) {
+ Cursor **handle = lua_touserdata(L, lua_upvalueindex(1));
+ if (!*handle)
+ return 0;
+ Cursor *cur = obj_ref_new(L, *handle, "vis.window.cursor");
+ if (!cur)
+ return 0;
+ *handle = view_cursors_next(cur);
+ return 1;
+}
+
+static int window_cursors_iterator(lua_State *L) {
+ Win *win = obj_ref_check(L, 1, "vis.window");
+ if (!win) {
+ lua_pushnil(L);
+ return 1;
+ }
+ Cursor **handle = lua_newuserdata(L, sizeof *handle);
+ *handle = view_cursors(win->view);
+ lua_pushcclosure(L, window_cursors_iterator_next, 1);
+ return 1;
+}
+
static const struct luaL_Reg window_funcs[] = {
{ "__index", window_index },
{ "__newindex", window_newindex },
+ { "cursors_iterator", window_cursors_iterator },
{ NULL, NULL },
};