diff options
| author | Marc André Tanner <mat@brain-dump.org> | 2016-04-21 09:50:23 +0200 |
|---|---|---|
| committer | Marc André Tanner <mat@brain-dump.org> | 2016-04-21 10:01:40 +0200 |
| commit | 07d8486f657dded76c6317550377962899f9152f (patch) | |
| tree | 9bb3aaf22df39b3161cbc3db427858f5ee5875e3 /vis-lua.c | |
| parent | 7b1f313436c09d4e41ba71fa0ad91326c4e16944 (diff) | |
| download | vis-07d8486f657dded76c6317550377962899f9152f.tar.gz vis-07d8486f657dded76c6317550377962899f9152f.tar.xz | |
vis-lua: add utility function to push a Filerange onto the Lua stack
Diffstat (limited to 'vis-lua.c')
| -rw-r--r-- | vis-lua.c | 26 |
1 files changed, 15 insertions, 11 deletions
@@ -232,6 +232,20 @@ static int newindex_common(lua_State *L) { return 0; } +static void pushrange(lua_State *L, Filerange *r) { + if (!text_range_valid(r)) { + lua_pushnil(L); + return; + } + lua_createtable(L, 0, 2); + lua_pushstring(L, "start"); + lua_pushunsigned(L, r->start); + lua_settable(L, -3); + lua_pushstring(L, "finish"); + lua_pushunsigned(L, r->end); + lua_settable(L, -3); +} + static const char *keymapping(Vis *vis, const char *keys, const Arg *arg) { lua_State *L = vis->lua; if (!func_ref_get(L, arg->v)) @@ -658,17 +672,7 @@ static int window_cursor_index(lua_State *L) { if (strcmp(key, "selection") == 0) { Filerange sel = view_cursors_selection_get(cur); - if (text_range_valid(&sel)) { - lua_createtable(L, 0, 2); - lua_pushstring(L, "start"); - lua_pushunsigned(L, sel.start); - lua_settable(L, -3); - lua_pushstring(L, "finish"); - lua_pushunsigned(L, sel.end); - lua_settable(L, -3); - } else { - lua_pushnil(L); - } + pushrange(L, &sel); return 1; } } |
