diff options
| author | Marc André Tanner <mat@brain-dump.org> | 2016-02-17 21:50:10 +0100 |
|---|---|---|
| committer | Marc André Tanner <mat@brain-dump.org> | 2016-02-18 16:50:40 +0100 |
| commit | a04408c5918376be63a1902fd71726dfff9edb3e (patch) | |
| tree | 32820f09792969a1889778ee395719d1b914def4 /vis-lua.c | |
| parent | 498723377cbf5cdb36d8b64f41b219a515a84175 (diff) | |
| download | vis-a04408c5918376be63a1902fd71726dfff9edb3e.tar.gz vis-a04408c5918376be63a1902fd71726dfff9edb3e.tar.xz | |
vis-lua: expose vis:textobject_register
Diffstat (limited to 'vis-lua.c')
| -rw-r--r-- | vis-lua.c | 24 |
1 files changed, 24 insertions, 0 deletions
@@ -404,6 +404,29 @@ static int textobject(lua_State *L) { return 1; } + +static Filerange textobject_lua(Vis *vis, Win *win, void *data, size_t pos) { + lua_State *L = vis->lua; + if (!func_ref_get(L, data) || !obj_ref_new(L, win, "vis.window")) + return text_range_empty(); + lua_pushunsigned(L, pos); + if (pcall(vis, L, 2, 2) != 0) + return text_range_empty(); + return text_range_new(luaL_checkunsigned(L, -2), luaL_checkunsigned(L, -1)); +} + +static int textobject_register(lua_State *L) { + int id = -1; + const void *func; + Vis *vis = obj_ref_check(L, 1, "vis"); + if (!vis || !lua_isfunction(L, 2) || !(func = func_ref_new(L))) + goto err; + id = vis_textobject_register(vis, 0, (void*)func, textobject_lua); +err: + lua_pushinteger(L, id); + return 1; +} + static int vis_index(lua_State *L) { Vis *vis = obj_ref_check(L, 1, "vis"); if (!vis) { @@ -469,6 +492,7 @@ static const struct luaL_Reg vis_lua[] = { { "motion", motion }, { "motion_register", motion_register }, { "textobject", textobject }, + { "textobject_register", textobject_register }, { "__index", vis_index }, { "__newindex", vis_newindex }, { NULL, NULL }, |
